﻿#Consort opinion values
grand_consort_position_opinion = {
	value = {
		value = regular_court_position_opinion
		#If the consort is ambitious, not demoted, and not forced, they will have extra opinion
		if = {
			limit = {
				scope:employee = {
					NOR = {
						has_opinion_modifier = {
							target = scope:liege
							modifier = forced_me_concubine_marriage_opinion
						}
						has_demoted_or_divorced_opinion_trigger = {
							TARGET = scope:liege
						}
					}
					OR = {
						has_trait = arrogant
						has_trait = ambitious
						has_trait = greedy
					}
				}
			}
			add = 5
		}
	}
}

#Bride Show values
bride_compensation_payment_value = { #To be used as a run-of-the-mill amount
	value = minor_gold_value
	if = { #Emperors and Kings will pay more
		limit = {
			root.primary_title.tier >= tier_kingdom
		}
		if = { 
			limit = {
				scope:potential_candidate = {
					any_close_family_member = {
						is_landed_or_landless_administrative = yes
						OR = {
							primary_title.tier >= tier_kingdom
							is_councillor_of = root
							is_powerful_vassal_of = root
						}
					}
				}
			}
			multiply = 0.90
		}
		else_if = { 
			limit = {
				scope:potential_candidate = {
					any_close_family_member = {
						is_landed_or_landless_administrative = yes
						primary_title.tier = tier_duchy
						OR = {	
							is_vassal_of = root
							is_tributary_of = root
						}
					}
				}
			}
			multiply = 0.80
		}
		else_if = { 
			limit = {
				scope:potential_candidate = {
					any_close_family_member = {
						is_landed_or_landless_administrative = yes
						OR = {	
							is_vassal_of = root
							is_tributary_of = root
						}
					}
				}
			}
			multiply = 0.70
		}
		else_if = { 
			limit = {
				scope:potential_candidate = {
					is_lowborn = no
				}
			}
			multiply = 0.50
		}
		else = {
			multiply = 0.30
		}
	}
	
	if = { #Dukes
		limit = {
			root.primary_title.tier = tier_duchy
		}
		if = { 
			limit = { #If a Count has a Prince in their court, somehow.
				scope:potential_candidate = {
					any_close_family_member = {
						is_landed_or_landless_administrative = yes
						primary_title.tier >= tier_kingdom
					}
				}
			}
			multiply = 0.85
		}
		if = { 
			limit = {
				scope:potential_candidate = {
					any_close_family_member = {
						is_landed_or_landless_administrative = yes
						OR = {
							is_councillor_of = root
							is_powerful_vassal_of = root
							AND = {
								primary_title.tier = tier_duchy
								is_tributary_of = root
							}
						}
					}
				}
			}
			multiply = 0.75
		}
		else_if = { 
			limit = {
				scope:potential_candidate = {
					any_close_family_member = {
						is_landed_or_landless_administrative = yes
						primary_title.tier = tier_county
						OR = {	
							is_vassal_of = root
							is_tributary_of = root
						}
					}
				}
			}
			multiply = 0.65
		}
		else_if = { 
			limit = {
				scope:potential_candidate = {
					any_close_family_member = {
						is_landed_or_landless_administrative = yes
						OR = {	
							is_vassal_of = root
							is_tributary_of = root
						}
					}
				}
			}
			multiply = 0.55
		}
		else_if = { 
			limit = {
				scope:potential_candidate = {
					is_lowborn = no
				}
			}
			multiply = 0.35
		}
		else = {
			multiply = 0.15
		}
	}
	
	if = { #Councillors are expensive
		limit = {
			scope:potential_candidate = {
				is_councillor = yes
			}
		}
		multiply = 1.2
	}
	if = { #Knights too
		limit = {
			scope:potential_candidate = {
				is_knight = yes
			}
		}
		multiply = {
			value = 1.1
			if = {
				limit = {
					scope:potential_candidate = {
						is_acclaimed = yes
					}
				}
				add = 0.05
			}
		}
	}
	if = { #And court positions
		limit = {
			scope:potential_candidate = {
				has_any_court_position = yes
			}
		}
		multiply = {
			value = 1.1
			if = {
				limit = {
					scope:potential_candidate = {
						has_court_position = court_physician_court_position
					}
				}
				add = 0.05
			}
		}
	}
	
	if = { #Physique
		limit = {
			scope:potential_candidate = {
				has_trait = physique_good_1
			}
		}
		multiply = 1.1
	}
	if = { #Physique
		limit = {
			scope:potential_candidate = {
				has_trait = physique_good_2
			}
		}
		multiply = 1.2
	}
	if = { #Physique
		limit = {
			scope:potential_candidate = {
				has_trait = physique_good_3
			}
		}
		multiply = 1.3
	}

	if = { #Intellect
		limit = {
			scope:potential_candidate = {
				has_trait = intellect_good_1
			}
		}
		multiply = 1.1
	}
	if = { #Intellect
		limit = {
			scope:potential_candidate = {
				has_trait = intellect_good_2
			}
		}
		multiply = 1.2
	}
	if = { #Intellect
		limit = {
			scope:potential_candidate = {
				has_trait = intellect_good_3
			}
		}
		multiply = 1.3
	}

	if = { #Beauty
		limit = {
			scope:potential_candidate = {
				has_trait = beauty_good_1
			}
		}
		multiply = 1.2
	}
	if = { #Beauty
		limit = {
			scope:potential_candidate = {
				has_trait = beauty_good_2
			}
		}
		multiply = 1.3
	}
	if = { #Beauty
		limit = {
			scope:potential_candidate = {
				has_trait = beauty_good_3
			}
		}
		multiply = 1.4
	}

	if = { #Pure_blooded
		limit = {
			scope:potential_candidate = {
				has_trait = pure_blooded
			}
		}
		multiply = 1.35
	}
	
	if = { #Skills
		limit = {
			scope:potential_candidate = {
				OR = {
					stewardship >= 9
					diplomacy >= 9
					learning >= 9
				}
			}
		}
		multiply = 1.05
	}
	if = { #Skills
		limit = {
			scope:potential_candidate = {
				OR = {
					stewardship >= 13
					diplomacy >= 13
					learning >= 13
				}
			}
		}
		multiply = 1.05
	}
	if = { #Skills
		limit = {
			scope:potential_candidate = {
				OR = {
					stewardship >= 17
					diplomacy >= 17
					learning >= 17
				}
			}
		}
		multiply = 1.05
	}
	if = { #Generous
		limit = {
			has_trait = generous
		}
		multiply = 1.15
	}
	if = { #Greedy
		limit = {
			has_trait = greedy
		}
		multiply = 0.75
	}

	#Inflation
	if = {
		limit = {
			culture = {
				has_cultural_era_or_later = culture_era_high_medieval
			}
		}
		multiply = 1.15
	}
	if = {
		limit = {
			culture = {
				has_cultural_era_or_later = culture_era_late_medieval
			}
		}
		multiply = 1.15
	}
	ceiling = yes
}

bride_show_candidate_weights_for_root_value = {
	value = 1
	if = { #Noble
		limit = {
			is_lowborn = no
		}
		add = 1
	}
	if = { #Beauty
		limit = {
			has_trait = beauty_good
		}
		add = {
			value = 1
			if = {
				limit = {
					has_trait = beauty_good_2
				}
				add = 1
			}
			if = {
				limit = {
					has_trait = beauty_good_3
				}
				add = 1
			}
		}
	}
	if = { #Intellect
		limit = {
			has_trait = intellect_good
		}
		add = {
			value = 1
			if = {
				limit = {
					has_trait = intellect_good_2
				}
				add = 1
			}
			if = {
				limit = {
					has_trait = intellect_good_3
				}
				add = 1
			}
		}
	}
	if = { #Physique
		limit = {
			has_trait = physique_good
		}
		add = {
			value = 1
			if = {
				limit = {
					has_trait = physique_good_2
				}
				add = 1
			}
			if = {
				limit = {
					has_trait = physique_good_3
				}
				add = 1
			}
		}
	}
	if = { #Beauty
		limit = {
			num_of_good_genetic_traits >= 2
		}
		add = {
			value = 1
			if = {
				limit = {
					num_of_good_genetic_traits >= 3
				}
				add = 1
			}
		}
	}
	if = { #Rare traits
		limit = {
			has_trait = fecund
		}
		add = 2
	}
	if = { #Rare traits
		limit = {
			has_trait = pure_blooded
		}
		add = 4
	}
	if = {
		limit = {
			is_knight = yes
		}
		add = {
			value = 5
			if = {
				limit = {
					is_acclaimed = yes
				}
				add = 5
			}
		}
	}
	if = {
		limit = {
			has_any_court_position = yes
		}
		add = {
			value = 10
			if = {
				limit = {
					has_court_position = court_physician_court_position
				}
				add = 10
			}
		}
	}
	if = { #Councillors
		limit = {
			is_councillor = yes
		}
		add = 15
	}
	if = { #Close relatives
		limit = {
			is_close_family_of = root
		}
		add = { #Children
			value = 75
			if = {
				limit = {
					is_child_of = root
				}
				add = 25
			}
		}
	}
}

#Favor values
favor_base_value_gain = 8

#Additions
favor_miniscule_value_gain = {
	add = favor_base_value_gain
	divide = 2
}
favor_minor_value_gain = {
	add = favor_base_value_gain
}
favor_medium_value_gain = {
	add = favor_base_value_gain
	add = favor_miniscule_value_gain
}
favor_high_value_gain = {
	add = favor_base_value_gain
	multiply = 2
}
favor_ultra_high_value_gain = {
	add = favor_high_value_gain
	add = favor_miniscule_value_gain
}

#Losses
favor_miniscule_value_loss = {
	value = 0
	subtract = favor_miniscule_value_gain
}
favor_minor_value_loss = {
	value = 0
	subtract = favor_minor_value_gain
}
favor_medium_value_loss = {
	value = 0
	subtract = favor_medium_value_gain
}
favor_high_value_loss = {
	value = 0
	subtract = favor_high_value_gain
}
favor_ultra_high_value_loss = {
	value = 0
	subtract = favor_ultra_high_value_gain
}

#Bonus for high-ranking consorts
favor_ps_bonus = { #The PS will have 6 additional months
	value = favor_minor_value_gain
	multiply = 6
}
favor_gc_bonus = { #The GC will have 3 additional months
	value = favor_minor_value_gain
	multiply = 3
}
favor_ss_bonus = { #SSs will have 1 additional month
	value = favor_minor_value_gain
}

favor_points = {
	value = 0

	##Additions##
	add = favor_points_additions
	
	##Subtractions##

	add = favor_points_subtractions

	#########Update to frequency#########
	if = {
		limit = { has_game_rule = consort_favor_bimonthly_on }
		multiply = 2
	}
	else_if = {
		limit = { has_game_rule = consort_favor_quarterly_on }
		multiply = 3
	}
	else_if = {
		limit = { has_game_rule = consort_favor_quadrimestral_on }
		multiply = 4
	}
	round = yes
	floor = yes
}

favor_points_additions = {
	value = 0
	#########Little competition#########
	# No favored consorts
	if = {
		limit = {
			scope:harem_liege = {
				NOT = {
					any_consort = { 
						is_valid_for_favor_system_trigger = { HAREM_LIEGE = scope:harem_liege }
						has_variable = favor
						var:favor >= favorite_consort_lower_limit
					}
				}
			}
		}
		add = {
			value = 4
			if = { # More if there are many unfavored consorts
				limit = {
					scope:harem_liege = {
						any_consort = { 
							is_valid_for_favor_system_trigger = { HAREM_LIEGE = scope:harem_liege }
							has_variable = favor
							var:favor < neutral_consort_lower_limit
							percent >= 0.7
						}
					}
				}
				add = 4
			}
			if = { # More if there are many unfavored consorts
				limit = {
					scope:harem_liege = {
						any_consort = { 
							is_valid_for_favor_system_trigger = { HAREM_LIEGE = scope:harem_liege }
							has_variable = favor
							var:favor < neutral_consort_lower_limit
							percent >= 0.9
						}
					}
				}
				add = 4
			}
		}
	}
	#Number of consorts
	if = {
		limit = { 
			scope:harem_liege = { 
				any_consort = { 
					is_valid_for_favor_system_trigger = { HAREM_LIEGE = scope:harem_liege }
					count <= 6
				}
			}
		}
		add = {
			#desc = favor_subtraction_many_consorts
			value = 2
			if = {
				limit = {
					scope:harem_liege = { 
						any_consort = { 
							is_valid_for_favor_system_trigger = { HAREM_LIEGE = scope:harem_liege }
							count <= 5
						}
					}
				}
				add = 2
			}
			if = {
				limit = {
					scope:harem_liege = { 
						any_consort = { 
							is_valid_for_favor_system_trigger = { HAREM_LIEGE = scope:harem_liege }
							count <= 4
						}
					}
				}
				add = 2
			}
		}
	}

	#########New consorts#########
	if = {
		limit = { 
			root = { 	
				has_character_flag = flag_new_consort
			}
		}
		add = {
			#desc = favor_addition_new_consort
			value = 2
			if = {
				limit = {
					root = { 	
						NOR = {
							has_character_modifier = beloved_consort_modifier
							has_character_modifier = favored_consort_modifier
							has_character_modifier =  favor_boost_modifier
							has_relation_soulmate = scope:harem_liege
							has_relation_lover = scope:harem_liege
						}
					}
				}
				add = 1
			}
		}
	}

	#########Youth#########
	if = {
		limit = { 
			root = { 	
				age <= 25
			}
		}
		add = {
			#desc = favor_addition_youth
			value = 2
			if = {
				limit = {
					root = { 	
						NOR = {
							has_character_modifier = beloved_consort_modifier
							has_character_modifier = favored_consort_modifier
							has_character_modifier = favor_boost_modifier
							has_relation_soulmate = scope:harem_liege
							has_relation_lover = scope:harem_liege
						}
					}
				}
				add = {
					value = 2
					if = {
						limit = {
							root = { 	
								age <= 20
							}
						}
						add = 2
					}
				}
			}
		}
	}

	#########Ranking#########
	#The PS
	if = {
		limit = {
			scope:harem_liege.primary_spouse ?= { 	
				this = root
			}
		}
		add = {
			#desc = favor_addition_ps
			value = 6
		}
	}
	#The GC
	if = {
		limit = { 
			root = { 	
				has_court_position = grand_consort_court_position
				is_demoted_consort_trigger = no
			}
		}
		add = {
			#desc = favor_addition_gc
			value = 4
		}
	}
	#Spouses
	if = {
		limit = { 
			root = { 	
				is_spouse_of = scope:harem_liege
				is_demoted_consort_trigger = no
				NOR = {
					this = scope:harem_liege.primary_spouse
					has_court_position = grand_consort_court_position
				}
			}
		}
		add = {
			#desc = favor_addition_ss
			value = 2
		}
	}

	#########Children#########
	#Number of children
	if = {
		limit = {
			root = {
				any_child = {
					is_child_of = scope:harem_liege
					is_alive = yes
					count > 0
				}
			}
		}
		root = {
			every_child = {
				limit = {
					is_child_of = scope:harem_liege
					is_alive = yes
				}
				add = {
					value = 2
					if = { #Eligible heirs
						limit = {
							character_gender_can_inherit_from_trigger = { CHARACTER = scope:harem_liege }
						}
						add = 2
					}
					if = { #Closer to the throne
						limit = {
							scope:harem_liege.primary_title = {
								place_in_line_of_succession = {
									target = prev
									value <= 3
								}
							}
						}
						add = 2
					}
					if = { #Player heir
						limit = {
							is_player_heir_of = scope:harem_liege
						}
						add = 2
					}
					if = { #Friends with liege
						limit = {
							has_relation_friend = scope:harem_liege
						}
						add = 2
					}
					if = { #Friends with liege
						limit = {
							has_relation_best_friend = scope:harem_liege
						}
						add = 4
					}
				}
			}
		}
	}
	#Pregnant consorts
	if = {
		limit = { 
			root = {  
				has_trait = pregnant
				pregnancy_assumed_father ?= {
					this = scope:harem_liege
				}
			}
		}
		add = {
			#desc = favor_addition_pregnant
			value = 6
			if = { #More if there are no children
				limit = { 
					scope:harem_liege = {  
						any_child = { 
							count = 0
						}
					}
				}
				add = 6
			}
			if = { #More if there are few children
				limit = { 
					scope:harem_liege = {  
						any_child = { 
							is_alive = yes
							count <= 4
						}
					}
				}
				add = 3
			}
			if = { #More if there are no children who can inherit
				limit = { 
					scope:harem_liege = {  
						any_child = { 
							character_gender_can_inherit_from_trigger = { CHARACTER = scope:harem_liege }
							count = 0
						}
					}
				}
				add = 6
			}
			if = { #More if there are few children who can inherit
				limit = { 
					scope:harem_liege = {  
						any_child = { 
							character_gender_can_inherit_from_trigger = { CHARACTER = scope:harem_liege }
							count <= 2
						}
					}
				}
				add = 3
			}
			if = { #Too few consorts
				limit = {
					scope:harem_liege = { 
						any_consort = { 
							is_valid_for_favor_system_trigger = { HAREM_LIEGE = scope:harem_liege }
							count <= 6
						}
					}
				}
				add = 2
			}
		}
	}
	#Recently served in bed
	if = {
		limit = {
			root = {
				has_variable = had_recent_sex_with
				var:had_recent_sex_with = scope:harem_liege
			}
		}
		add = 1
	}

	#########Relation#########
	#Friends
	if = {
		limit = { 
			root = {  
				has_relation_friend = scope:harem_liege
				has_variable = favor
			}
		}
		add = {
			#desc = favor_addition_friend
			value = 8
			if = { #Forgotten
				limit = { 
					root = {  
						has_variable = favor
						var:favor < unfavored_consort_lower_limit
					}
				}
				add = 34
			}
			if = { #Neutral
				limit = { 
					root = {  
						var:favor >= unfavored_consort_lower_limit
						var:favor < neutral_consort_lower_limit
					}
				}
				add = 98
			}
			if = { #Not favored or beloved
				limit = { 
					root = {  
						var:favor >= neutral_consort_lower_limit
						var:favor < favorite_consort_lower_limit
					}
				}
				add = 118
			}
		}
	}
	#BFF
	if = {
		limit = { 
			root = {  
				has_relation_best_friend = scope:harem_liege
				has_variable = favor
			}
		}
		add = {
			#desc = favor_addition_bff
			value = 12
			if = { #Forgotten
				limit = { 
					root = {  
						var:favor < unfavored_consort_lower_limit
					}
				}
				add = 40
			}
			if = { #Unfavored
				limit = { 
					root = {  
						var:favor >= unfavored_consort_lower_limit
						var:favor < neutral_consort_lower_limit
					}
				}
				add = 98
			}
			if = { #Not favored or beloved
				limit = { 
					root = {  
						var:favor >= neutral_consort_lower_limit
						var:favor < favorite_consort_lower_limit
					}
				}
				add = 118
			}
		}
	}
	#Lover
	if = {
		limit = { 
			root = {  
				has_relation_lover = scope:harem_liege
				has_variable = favor
			}
		}
		add = {
			#desc = favor_addition_soulmate
			value = 12
			if = { #Forgotten
				limit = { 
					root = {  
						var:favor < unfavored_consort_lower_limit
					}
				}
				add = 40
			}
			if = { #Unfavored
				limit = { 
					root = {  
						var:favor >= unfavored_consort_lower_limit
						var:favor < neutral_consort_lower_limit
					}
				}
				add = 98
			}
			if = { #Not favored or beloved
				limit = { 
					root = {  
						var:favor >= neutral_consort_lower_limit
						var:favor < favorite_consort_lower_limit
					}
				}
				add = 118
			}
		}
	}
	#Soulmate
	if = {
		limit = { 
			root = {  
				has_relation_soulmate = scope:harem_liege
				has_variable = favor
			}
		}
		add = {
			#desc = favor_addition_soulmate
			value = 18
			if = { #Forgotten
				limit = { 
					root = {  
						var:favor < unfavored_consort_lower_limit
					}
				}
				add = 40
			}
			if = { #Neutral
				limit = { 
					root = {  
						var:favor >= unfavored_consort_lower_limit
						var:favor < neutral_consort_lower_limit
					}
				}
				add = 98
			}
			if = { #Not favored or beloved
				limit = { 
					root = {  
						var:favor >= neutral_consort_lower_limit
						var:favor < favorite_consort_lower_limit
					}
				}
				add = 118
			}
		}
	}
	# Connections to authorities
	if = {
		limit = {
			scope:harem_liege = {
				any_courtier = {
					OR = {
						is_head_of_the_harem_trigger = {
							LIEGE = scope:harem_liege
						}
						is_parent_of = scope:harem_liege
						trigger_if = {
							limit = {
								scope:harem_liege = {
									religion = religion:islam_religion
								}
							}
							is_valid_harem_member_trigger = {
								LIEGE = scope:harem_liege
							}
						}
					}
					NOR = {
						has_relation_rival = scope:harem_liege
						has_relation_nemesis = scope:harem_liege
						is_consort_of = scope:harem_liege

						has_relation_rival = root
						has_relation_nemesis = root
					}
					OR = {
						has_relation_friend = root
						has_relation_best_friend = root

						has_relation_lover = root
						has_relation_soulmate = root

						has_hook = root
					}
				}
			}
		}
		add = {
			value = 0
			if = { # The head of the harem
				limit = {
					scope:harem_liege = {
						any_courtier = {
							OR = {
								is_head_of_the_harem_trigger = {
									LIEGE = scope:harem_liege
								}
								is_parent_of = scope:harem_liege
							}
							NOR = {
								has_relation_rival = scope:harem_liege
								has_relation_nemesis = scope:harem_liege
								is_consort_of = scope:harem_liege
		
								has_relation_rival = root
								has_relation_nemesis = root
							}
							OR = {
								has_relation_friend = root
								has_relation_best_friend = root
		
								has_relation_lover = root
								has_relation_soulmate = root
		
								has_hook = root
							}
						}
					}
				}
				add = 2
				if = {
					limit = {
						scope:harem_liege = {
							any_courtier = {
								OR = {
									is_head_of_the_harem_trigger = {
										LIEGE = scope:harem_liege
									}
									is_parent_of = scope:harem_liege
								}
								NOR = {
									has_relation_rival = scope:harem_liege
									has_relation_nemesis = scope:harem_liege
									is_consort_of = scope:harem_liege
			
									has_relation_rival = root
									has_relation_nemesis = root
								}
								OR = {
									has_relation_friend = root
									has_relation_best_friend = root
								}
							}
						}
					}
					add = 2	
				}
			}
			else_if = { # Another authority
				limit = {
					scope:harem_liege = {
						religion = religion:islam_religion
						any_courtier = {
							is_valid_harem_member_trigger = {
								LIEGE = scope:harem_liege
							}
							NOR = {
								has_relation_rival = scope:harem_liege
								has_relation_nemesis = scope:harem_liege
								is_consort_of = scope:harem_liege
		
								has_relation_rival = root
								has_relation_nemesis = root
							}
							OR = {
								has_relation_friend = root
								has_relation_best_friend = root
		
								has_relation_lover = root
								has_relation_soulmate = root
		
								has_hook = root
							}
						}
					}
				}
				add = 1
				if = {
					limit = {
						scope:harem_liege = {
							any_courtier = {
								is_valid_harem_member_trigger = {
									LIEGE = scope:harem_liege
								}
								NOR = {
									has_relation_rival = scope:harem_liege
									has_relation_nemesis = scope:harem_liege
									is_consort_of = scope:harem_liege
			
									has_relation_rival = root
									has_relation_nemesis = root
								}
								OR = {
									has_relation_friend = root
									has_relation_best_friend = root
								}
							}
						}
					}
					add = 1	
				}
			}
		}
	}
	# Connections to other courtiers
	if = { # The Chief Eunuch
		limit = {
			scope:harem_liege = {
				any_court_position_holder = {
					type = chief_eunuch_court_position
					OR = {
						has_relation_friend = root
						has_relation_best_friend = root

						has_relation_lover = root
						has_relation_soulmate = root

						has_hook = root
						root = {
							has_hook = prev
						}
					}
				}
			}
		}
		add = 2
	}
	if = { # The Lady-in-Waiting
		limit = {
			scope:harem_liege = {
				any_court_position_holder = {
					type = lady_in_waiting_court_position
					OR = {
						has_relation_friend = root
						has_relation_best_friend = root

						has_relation_lover = root
						has_relation_soulmate = root

						has_hook = root
						root = {
							has_hook = prev
						}
					}
				}
			}
		}
		add = 2
	}

	#########Beauty#########
	#Comely
	if = {
		limit = { 
			root = {  
				has_trait = beauty_good_1
				age <= 45
			}
		}
		add = {
			#desc = favor_addition_comely
			value = 6
		}
	}
	#Handsome
	if = {
		limit = { 
			root = {  
				has_trait = beauty_good_2
				age <= 45
			}
		}
		add = {
			#desc = favor_addition_handsome
			value = 10
		}
	}
	#Beautiful
	if = {
		limit = { 
			root = {  
				has_trait = beauty_good_3
				age <= 45
			}
		}
		add = {
			#desc = favor_addition_beautiful
			value = 14
		}
	}
	#########Intelligence, physique and pure_blooded#########
	#Quick
	if = {
		limit = { 
			root = {  
				has_trait = intellect_good_1
			}
		}
		add = {
			#desc = favor_addition_quick
			value = 4
		}
	}
	#Intelligent
	if = {
		limit = { 
			root = {  
				has_trait = intellect_good_2
			}
		}
		add = {
			#desc = favor_addition_intelligent
			value = 6
		}
	}
	#Genius
	if = {
		limit = { 
			root = {  
				has_trait = intellect_good_3
			}
		}
		add = {
			#desc = favor_addition_genius
			value = 8
		}
	}

	#Hale
	if = {
		limit = { 
			root = {  
				has_trait = physique_good_1
			}
		}
		add = {
			#desc = favor_addition_hale
			value = 4
		}
	}
	#Robust
	if = {
		limit = { 
			root = {  
				has_trait = physique_good_2
			}
		}
		add = {
			#desc = favor_addition_robust
			value = 6
		}
	}
	#Amazonian
	if = {
		limit = { 
			root = {  
				has_trait = physique_good_3
			}
		}
		add = {
			#desc = favor_addition_amazonian
			value = 8
		}
	}

	#Pure_blooded
	if = {
		limit = { 
			root = {  
				has_trait = pure_blooded
			}
		}
		add = {
			#desc = favor_addition_pure_blooded
			value = 14
		}
	}

	#########Lineage#########
	#Noble background
	if = {
		limit = { 
			root = {  
				is_lowborn = no
			}
		}
		add = {
			#desc = favor_addition_noble
			value = 2
		}
	}
	#Child of vassals
	if = {
		limit = { 
			root = {  
				any_close_family_member = {
					is_landed_or_landless_administrative = yes
					highest_held_title_tier >= tier_county
					max_military_strength < scope:harem_liege.max_military_strength
					OR = {
						is_vassal_of = scope:harem_liege
						AND = { #It applies also to fellow powerful vassals
							exists = scope:harem_liege.liege
							liege ?= scope:harem_liege.liege
							OR = {	
								is_powerful_vassal_of = scope:harem_liege.liege
								is_councillor_of = scope:harem_liege.liege
							}
							NOT = {
								this = scope:harem_liege.liege
							}
						}
					}
					NOT = { is_child_of = scope:harem_liege }
					NAND = { #Dominant families have another calculation
						government_allows = administrative
						house ?= { is_dominant_family = yes }
						OR = {
							AND = {
								exists = scope:harem_liege.top_liege
								top_liege ?= scope:harem_liege.top_liege
							}
							AND = {
								is_vassal_or_below_of = scope:harem_liege
							}
						}
					}
				}
			}
		}
		add = {
			value = 4
			#desc = favor_addition_good_lineage
			if = {
				limit = { 
					root = {  
						any_close_family_member = {
							is_landed_or_landless_administrative = yes
							max_military_strength < scope:harem_liege.max_military_strength
							OR = {
								is_powerful_vassal_of = scope:harem_liege
								is_councillor_of = scope:harem_liege
								AND = { #It applies also to fellow powerful vassals
									exists = scope:harem_liege.liege
									liege ?= scope:harem_liege.liege
									OR = {	
										is_powerful_vassal_of = scope:harem_liege.liege
										is_councillor_of = scope:harem_liege.liege
									}
								}
							}
							NAND = { #Dominant families have another calculation
								government_allows = administrative
								house ?= { is_dominant_family = yes }
								OR = {
									AND = {
										exists = scope:harem_liege.top_liege
										top_liege ?= scope:harem_liege.top_liege
									}
									AND = {
										is_vassal_or_below_of = scope:harem_liege
									}
								}
							}
						}
					}
				}
				add = 6
			}
		}
	}
	#Powerful lineage
	if = {
		limit = { 
			root = {  
				any_close_family_member = {
					is_landed_or_landless_administrative = yes
					OR = {
						is_liege_or_above_of = scope:harem_liege
						max_military_strength >= scope:harem_liege.max_military_strength
						AND = { #Dominant families
							government_allows = administrative
							house ?= { is_dominant_family = yes }
							OR = {
								AND = {
									exists = scope:harem_liege.top_liege
									top_liege ?= scope:harem_liege.top_liege
								}
								AND = {
									is_vassal_or_below_of = scope:harem_liege
								}
							}
						}
					}
					NOT = { is_child_of = scope:harem_liege }
				}
			}
		}
		add = {
			#desc = favor_addition_powerful_lineage
			value = 12
		}
	}

	#########Diplomacy#########
	if = {
		limit = { 
			root = {  
				diplomacy >= 12
			}
		}
		add = {
			#desc = favor_diplomacy
			value = root.diplomacy
			divide = 2
			round = yes
			max = 10
		}
	}

	#########Modifiers#########
	if = { #For the one who has, more will be given...
		limit = { 
			root = {
				has_character_modifier = beloved_consort_modifier
			}
			scope:harem_liege = {
				any_consort = {
					has_character_modifier = beloved_consort_modifier
					count = 1
				}
			}
		}
		add = {
			#desc = favor_addition_beloved
			value = 4
			if = {
				limit = { 
					root = {
						NOR = { 
							has_relation_lover = scope:harem_liege
							has_relation_soulmate = scope:harem_liege 
							has_character_modifier = favor_boost_modifier
						}
					}
				}
				add = 10
			}
		}
	}
	else_if = { #For the one who has, more will be given...
		limit = { 
			root = {
				has_character_modifier = favored_consort_modifier
			}
			scope:harem_liege = {
				OR = {
					AND = { #There's a max of 1 favorite if liege has 6 consorts or less
						any_consort = {
							is_valid_for_favor_system_trigger = { HAREM_LIEGE = scope:harem_liege }
							count <= 6
						}
						any_consort = {
							has_character_modifier = favored_consort_modifier
							count <= 1
						}
					}
					AND = { #There's a max of 1 favorite if liege has 6 consorts or less
						any_consort = {
							is_valid_for_favor_system_trigger = { HAREM_LIEGE = scope:harem_liege }
							count > 6
						}
						any_consort = {
							has_character_modifier = favored_consort_modifier
							count <= 2
						}
					}
				}
			}
		}
		add = {
			#desc = favor_addition_favorite
			value = 2
			if = {
				limit = { 
					root = {
						NOR = { 
							has_relation_lover = scope:harem_liege
							has_relation_soulmate = scope:harem_liege 
							has_character_modifier = favor_boost_modifier
						}
					}
				}
				add = 8
			}
		}
	}

	if = {
		limit = {
			OR = {
				has_character_modifier = shu_fei_conception_medicine_modifier
				has_character_modifier = hua_fei_fragrance_modifier
			}
		}
		add = 4
	}

	#########Favor boost#########
	if = {
		limit = {
			root = {  
				has_character_modifier = favor_boost_modifier
				has_variable = favor
			}
		}
		add = {
			#desc = favor_addition_soulmate
			value = 8
			if = { #Forgotten
				limit = { 
					root = {  
						var:favor < unfavored_consort_lower_limit
					}
				}
				add = 48
			}
			if = { #Unfavored
				limit = { 
					root = {  
						var:favor >= unfavored_consort_lower_limit
						var:favor < neutral_consort_lower_limit
					}
				}
				add = 106
			}
			if = { #Not favored or beloved
				limit = { 
					root = {  
						var:favor >= neutral_consort_lower_limit
						var:favor < favorite_consort_lower_limit
					}
				}
				add = 126
			}
		}
	}

	#########Travel#########
	#You're invited to travel
	if = {
		limit = { 
			scope:harem_liege = {
				is_travelling = yes
			}
			root = {
				is_travelling = yes
				current_travel_plan ={
					travel_plan_owner = scope:harem_liege
				}
			}
		}
		add = {
			#desc = favor_addition_invited_consort
			value = 4
		}
	}

	#########Traits#########
	#root traits
	if = { #Seducer
		limit = { 
			root = {
				has_trait = seducer
			}
		}
		add = 6
	}
	if = { #Poet
		limit = { 
			root = {
				has_trait = poet
			}
		}
		add = 6
	}
	if = { #Lustful
		limit = { 
			root = {
				has_trait = lustful
			}
		}
		add = {
			value = 4
			if = {
				limit = {
					scope:harem_liege = {
						has_trait = lustful
					}
				}
				add = 4
			}
		}
	}
	if = { #Gregarious
		limit = { 
			root = {
				has_trait = gregarious
			}
		}
		add = {
			value = 4
			if = {
				limit = {
					scope:harem_liege = {
						has_trait = gregarious
					}
				}
				add = 2
			}
		}
	}
	if = { #Chaste
		limit = { 
			root = {
				has_trait = chaste
			}
			scope:harem_liege = {
				has_trait = chaste
			}
		}
		add = 4
	}
	if = { #Gluttonous
		limit = { 
			root = {
				has_trait = gluttonous
			}
			scope:harem_liege = {
				has_trait = gluttonous
				NOT = { has_trait = arbitrary }
			}
		}
		add = 4
	}

	if = { #Good genetics
		limit = { 
			root = {
				num_of_good_genetic_traits > 1
			}
		}
		add = {
			#desc = favor_addition_good_genetics
			value = 2
			if = {
				limit = { 
					root = {
						num_of_good_genetic_traits > 2
					}
				}
				add = 2
			}
		}
	}

	if = { #Confider
		limit = { 
			root = {
				has_trait = confider
			}
			scope:harem_liege = {
				has_trait = confider
			}
		}
		add = 4
	}
	if = { #Athletic
		limit = { 
			root = {
				has_trait = athletic
			}
		}
		add = {
			value = 2
			if = {
				limit = {
					scope:harem_liege = {
						has_trait = athletic
					}
				}
				add = 2
			}
		}
	}
	if = { #Improvident
		limit = { 
			root = {
				has_trait = improvident
			}
			scope:harem_liege = {
				has_trait = generous
			}
		}
		add = 2
	}
	#harem_liege traits
	if = { # If harem_liege is compassionate, consorts will gain more favor
		limit = {
			scope:harem_liege = {
				OR = {	
					has_trait = compassionate
					has_trait = forgiving
					has_trait = just
				}
			}
			root = {
				NOR = {
					has_trait = sadistic
					has_trait = callous
					has_trait = vengeful
				}
				trigger_if = {
					limit = {
						scope:harem_liege = {
							has_trait = just
						}
					}
					NOT = {
						has_trait = arbitrary
					}
				}
			}
		}
		add = 4
	}
	if = { # Trusting lieges will visit their consorts more often
		limit = {
			scope:harem_liege = {
				has_trait = trusting
			}
		}
		add = 1.25
	}
	if = { #If the liege is lustful, they will visit their consorts quite often
		limit = { 
			scope:harem_liege = {
				has_trait = lustful
			}
		}
		multiply = 1.2
	}
	if = { #If the liege is gregarious, they will visit their consorts quite often
		limit = { 
			scope:harem_liege = {
				has_trait = gregarious
			}
		}
		multiply = 1.15
	}
	if = { #If the liege is chaste, consorts will lose favore more quickly
		limit = { 
			scope:harem_liege = {
				has_trait = chaste
			}
		}
		multiply = 0.9
	}
	if = { #If the liege is shy, consorts will lose favore more quickly
		limit = { 
			scope:harem_liege = {
				has_trait = shy
			}
		}
		multiply = 0.9
	}
	if = { #If the liege is craven, consorts will lose favore more quickly
		limit = { 
			scope:harem_liege = {
				has_trait = craven
			}
		}
		multiply = 0.95
	}
	if = { #If the liege is paranoid, consorts will lose favore more quickly
		limit = { 
			scope:harem_liege = {
				has_trait = paranoid
			}
		}
		multiply = 0.9
	}
	if = { #If the liege is reclusive, consorts will lose favore more quickly
		limit = { 
			scope:harem_liege = {
				has_trait = reclusive
			}
		}
		multiply = 0.9
	}

	#Stress levels
	#Root#
	if = { #Level 1
		limit = { 
			root = {
				stress_level = 1
			}
		}
		multiply = 0.933
	}
	if = { #Level 2
		limit = { 
			root = {
				stress_level = 2
			}
		}
		multiply = 0.767
	}
	if = { #Level 3
		limit = { 
			root = {
				stress_level = 3
			}
		}
		multiply = 0.6
	}
	#Liege#
	if = { #Level 1
		limit = { 
			scope:harem_liege = {
				stress_level = 1
			}
		}
		multiply = 0.833
	}
	if = { #Level 2
		limit = { 
			scope:harem_liege = {
				stress_level = 2
			}
		}
		multiply = 0.667
	}
	if = { #Level 3
		limit = { 
			scope:harem_liege = {
				stress_level = 3
			}
		}
		multiply = 0.5
	}

	#########War#########
	if = {
		limit = {
			scope:harem_liege = {
				is_at_war = yes
			}
		}
		multiply = {
			value = {
				value = 0.9
				if = {
					limit = {
						scope:harem_liege = {
							any_character_war = { is_war_leader = scope:harem_liege }
						}
					}
					add = -0.1
				}
			}
		}
	}

	#########Balancing favor#########
	if = {
		limit = {
			scope:harem_liege = {
				any_court_position_holder = {
					type = grand_consort_court_position
					aptitude:grand_consort_court_position >= 3
					has_character_flag = gc_balancing_favor_flag
				}
			}
		}
		if = { #Subtract more to the favored ones
			limit = {
				root = {
					has_variable = favor
					var:favor = beloved_consort_upper_limit
				}
			}
			if = {
				limit = {
					scope:harem_liege = {
						any_court_position_holder = {
							type = grand_consort_court_position
							aptitude:grand_consort_court_position = 5
						}
					}
				}
				multiply = 0.1
			}
			else_if = {
				limit = {
					scope:harem_liege = {
						any_court_position_holder = {
							type = grand_consort_court_position
							aptitude:grand_consort_court_position = 4
						}
					}
				}
				multiply = 0.15
			}
			else_if = {
				limit = {
					scope:harem_liege = {
						any_court_position_holder = {
							type = grand_consort_court_position
							aptitude:grand_consort_court_position = 3
						}
					}
				}
				multiply = 0.2
			}
		}
		else_if = { #Subtract more to the favored ones
			limit = {
				root = {
					has_variable = favor
					var:favor >= beloved_consort_lower_limit
				}
			}
			if = {
				limit = {
					scope:harem_liege = {
						any_court_position_holder = {
							type = grand_consort_court_position
							aptitude:grand_consort_court_position = 5
						}
					}
				}
				multiply = 0.15
			}
			else_if = {
				limit = {
					scope:harem_liege = {
						any_court_position_holder = {
							type = grand_consort_court_position
							aptitude:grand_consort_court_position = 4
						}
					}
				}
				multiply = 0.2
			}
			else_if = {
				limit = {
					scope:harem_liege = {
						any_court_position_holder = {
							type = grand_consort_court_position
							aptitude:grand_consort_court_position = 3
						}
					}
				}
				multiply = 0.25
			}
		}
		else_if = { #Subtract more to the favored ones
			limit = {
				root = {
					has_variable = favor
					var:favor >= favorite_consort_lower_limit
				}
			}
			if = {
				limit = {
					scope:harem_liege = {
						any_court_position_holder = {
							type = grand_consort_court_position
							aptitude:grand_consort_court_position = 5
						}
					}
				}
				multiply = 0.3
			}
			else_if = {
				limit = {
					scope:harem_liege = {
						any_court_position_holder = {
							type = grand_consort_court_position
							aptitude:grand_consort_court_position = 4
						}
					}
				}
				multiply = 0.35
			}
			else_if = {
				limit = {
					scope:harem_liege = { 
						any_court_position_holder = {
							type = grand_consort_court_position
							aptitude:grand_consort_court_position = 3
						}
					}
				}
				multiply = 0.4
			}
		}
		else_if = { #Add less to high-neutral ones
			limit = {
				root = {
					has_variable = favor
					var:favor >= 482
				}
			}
			if = {
				limit = {
					scope:harem_liege = {
						any_court_position_holder = {
							type = grand_consort_court_position
							aptitude:grand_consort_court_position = 5
						}
					}
				}
				multiply = 0.7
			}
			else_if = {
				limit = {
					scope:harem_liege = {
						any_court_position_holder = {
							type = grand_consort_court_position
							aptitude:grand_consort_court_position = 4
						}
					}
				}
				multiply = 0.75
			}
			else_if = {
				limit = {
					scope:harem_liege = {
						any_court_position_holder = {
							type = grand_consort_court_position
							aptitude:grand_consort_court_position = 3
						}
					}
				}
				multiply = 0.8
			}
		}
		else_if = { #Add more to the unfavored ones
			limit = {
				root = {
					has_variable = favor
					var:favor >= unfavored_consort_lower_limit
				}
			}
			add = 20
			if = {
				limit = {
					scope:harem_liege = {
						any_court_position_holder = {
							type = grand_consort_court_position
							aptitude:grand_consort_court_position = 5
						}
					}
				}
				multiply = 1.6
			}
			else_if = {
				limit = {
					scope:harem_liege = {
						any_court_position_holder = {
							type = grand_consort_court_position
							aptitude:grand_consort_court_position = 4
						}
					}
				}
				multiply = 1.55
			}
			else_if = {
				limit = {
					scope:harem_liege = {
						any_court_position_holder = {
							type = grand_consort_court_position
							aptitude:grand_consort_court_position = 3
						}
					}
				}
				multiply = 1.5
			}
		}
		else_if = { #Add more to the unfavored ones
			limit = {
				root = {
					has_variable = favor
					var:favor >= 5
				}
			}
			add = 25
			if = {
				limit = {
					scope:harem_liege = {
						any_court_position_holder = {
							type = grand_consort_court_position
							aptitude:grand_consort_court_position = 5
						}
					}
				}
				multiply = 1.8
			}
			else_if = {
				limit = {
					scope:harem_liege = {
						any_court_position_holder = {
							type = grand_consort_court_position
							aptitude:grand_consort_court_position = 4
						}
					}
				}
				multiply = 1.75
			}
			else_if = {
				limit = {
					scope:harem_liege = {
						any_court_position_holder = {
							type = grand_consort_court_position
							aptitude:grand_consort_court_position = 3
						}
					}
				}
				multiply = 1.7
			}
		}
		else_if = { #Add more to the unfavored ones
			limit = {
				root = {
					has_variable = favor
					var:favor = 0
				}
			}
			add = 30
			if = {
				limit = {
					scope:harem_liege = {
						any_court_position_holder = {
							type = grand_consort_court_position
							aptitude:grand_consort_court_position = 5
						}
					}
				}
				multiply = 2.2
			}
			else_if = {
				limit = {
					scope:harem_liege = {
						any_court_position_holder = {
							type = grand_consort_court_position
							aptitude:grand_consort_court_position = 4
						}
					}
				}
				multiply = 2.1
			}
			else_if = {
				limit = {
					scope:harem_liege = {
						any_court_position_holder = {
							type = grand_consort_court_position
							aptitude:grand_consort_court_position = 3
						}
					}
				}
				multiply = 1
			}
		}
	}
	if = { #Bad aptitude widens the gap
		limit = {
			scope:harem_liege = {
				any_court_position_holder = {
					type = grand_consort_court_position
					aptitude:grand_consort_court_position <= 2
					has_character_flag = gc_balancing_favor_flag
				}
			}
		}
		if = {
			limit = {
				root = {
					NOT = { has_character_flag = gc_balancing_favor_flag }
				}
			}
			if = { # It's harder to reduce favor for favorites
				limit = {
					root = {
						has_variable = favor
						var:favor >= favorite_consort_lower_limit
					}
				}
				if = {
					limit = {
						scope:harem_liege = {
							any_court_position_holder = {
								type = grand_consort_court_position
								aptitude:grand_consort_court_position = 2
							}
						}
					}
					multiply = 0.9
				}
				else_if = {
					limit = {
						scope:harem_liege = {
							any_court_position_holder = {
								type = grand_consort_court_position
								aptitude:grand_consort_court_position = 1
							}
						}
					}
					multiply = 0.8
				}
			}
			else_if = { # Subtract from the neutral ones
				limit = {
					root = {
						has_variable = favor
						var:favor >= neutral_consort_lower_limit
					}
				}
				if = {
					limit = {
						scope:harem_liege = {
							any_court_position_holder = {
								type = grand_consort_court_position
								aptitude:grand_consort_court_position = 2
							}
						}
					}
					multiply = 0.85
				}
				else_if = {
					limit = {
						scope:harem_liege = {
							any_court_position_holder = {
								type = grand_consort_court_position
								aptitude:grand_consort_court_position = 1
							}
						}
					}
					multiply = 0.75
				}
			}
			else = { #Add more to the unfavored ones
				if = {
					limit = {
						scope:harem_liege = {
							any_court_position_holder = {
								type = grand_consort_court_position
								aptitude:grand_consort_court_position = 2
							}
						}
					}
					multiply = 0.8
				}
				else_if = {
					limit = {
						scope:harem_liege = {
							any_court_position_holder = {
								type = grand_consort_court_position
								aptitude:grand_consort_court_position = 1
							}
						}
					}
					multiply = 0.7
				}
			}
		}
		else = { #The GC will add more favor to themselves
			if = {
				limit = {
					scope:harem_liege = {
						any_court_position_holder = {
							type = grand_consort_court_position
							aptitude:grand_consort_court_position = 2
						}
					}
				}
				multiply = 1.15
			}
			else = {
				multiply = 1.25
			}
		}
	}

	#########Attraction to the right gender#########
	if = {
		limit = {
			root = {
				NOT = { is_attracted_to_gender_of = scope:harem_liege }
			}
		}
		multiply = 0.75
	}
	if = {
		limit = {
			scope:harem_liege = {
				NOT = { is_attracted_to_gender_of = root }
			}
		}
		multiply = 0.5
	}
}

favor_points_subtractions = {
	value = 0
	subtract = {
		#desc = favor_subtraction_base_loss
		value = {
			value = 4
			if = { #More loss if neutral
				limit = { 
					root = {
						has_variable = favor
						var:favor >= neutral_consort_lower_limit
					}
				}
				add = 4
			}
			if = {
				limit = {
					root = {
						OR = {
							has_character_modifier = favored_consort_modifier
							has_character_modifier = favor_boost_modifier
							has_relation_lover = scope:harem_liege
							AND = {
								has_variable = favor
								var:favor >= favorite_consort_lower_limit
								var:favor < beloved_consort_lower_limit
							}
						}
					}
				}
				if = { # If there are more than 2 favorites and less than 7 consorts
					limit = {
						scope:harem_liege = {
							any_consort = {
								is_valid_for_favor_system_trigger = { HAREM_LIEGE = scope:harem_liege }
								count <= 6
							}
							any_consort = {
								OR = {
									has_character_modifier = favored_consort_modifier
									has_character_modifier = favor_boost_modifier
									has_relation_lover = scope:harem_liege
									AND = {
										has_variable = favor
										var:favor >= favorite_consort_lower_limit
										var:favor < beloved_consort_lower_limit
									}
								}
								count >= 2
							}
						}
					}
					add = 8
				}
				if = { # There are more than 2 favorites
					limit = {
						scope:harem_liege = {
							any_consort = {
								OR = {
									has_character_modifier = favored_consort_modifier
									has_character_modifier = favor_boost_modifier
									has_relation_lover = scope:harem_liege
									AND = {
										has_variable = favor
										var:favor >= favorite_consort_lower_limit
										var:favor < beloved_consort_lower_limit
									}
								}
								count >= 3
							}
						}
					}
					add = 12
					if = {
						limit = { # There are more than 3 favorites
							scope:harem_liege = {
								any_consort = {
									OR = {
										has_character_modifier = favored_consort_modifier
										has_character_modifier = favor_boost_modifier
										has_relation_lover = scope:harem_liege
										AND = {
											has_variable = favor
											var:favor >= favorite_consort_lower_limit
											var:favor < beloved_consort_lower_limit
										}
									}
									count >= 4
								}
							}
						}
						add = 18
					}
				}
			}

			if = {
				limit = {
					root = {
						OR = {
							has_character_modifier = beloved_consort_modifier
							has_relation_soulmate = scope:harem_liege
							AND = {	
								has_variable = favor
								var:favor >= beloved_consort_lower_limit
							}
						}
					}
				}
				if = { # There is more than a beloved consort
					limit = {
						scope:harem_liege = {
							any_consort = {
								OR = {
									has_character_modifier = beloved_consort_modifier
									has_relation_soulmate = scope:harem_liege
									AND = {	
										has_variable = favor
										var:favor >= beloved_consort_lower_limit
									}
								}
								count >= 2
							}
						}
					}
					add = 28
				}
				if = { # There are more than 2 beloved consorts
					limit = {
						scope:harem_liege = {
							any_consort = {
								OR = {
									has_character_modifier = beloved_consort_modifier
									has_relation_soulmate = scope:harem_liege
									AND = {	
										has_variable = favor
										var:favor >= beloved_consort_lower_limit
									}
								}
								count >= 3
							}
						}
					}
					add = 48
				}
			}
		}
	}

	#########Demoted consorts#########
	if = {
		limit = { 
			root = {
				is_demoted_consort_trigger = yes
			}
		}
		subtract = {
			#desc = favor_subtraction_demoted_consort
			value = {
				value = 12
				if = {
					limit = { 
						root = {
							has_character_modifier = demoted_primary_spouse_modifier
						}
					}
					add = 10
				}
			}
		}
	}

	#########Relation#########
	#Rivals
	if = {
		limit = { 
			root = {
				has_relation_rival = scope:harem_liege
			}
		}
		subtract = {
			#desc = favor_subtraction_rival
			value = 16
		}
	}
	#Nemesis
	if = {
		limit = { 
			root = {
				has_relation_nemesis = scope:harem_liege
			}
		}
		subtract = {
			#desc = favor_subtraction_nemesis
			value = 28
		}
	}
	# Forbidden lovers
	if = {
		limit = {
			scope:harem_liege = {
				NOT = { faith = { has_doctrine = tenet_polyamory } }
			}
			root = {
				OR = {
					has_trait = adulterer
					has_trait = fornicator
				}
				OR = {
					any_relation = {
						type = lover
						NOR = { 
							this = scope:harem_liege
							is_consort_of = root
						}
					}
					any_relation = {
						type = soulmate
						NOR = { 
							this = scope:harem_liege
							is_consort_of = root
						}
					}
				}
			}
		}
		subtract = 16
	}

	#########Beauty#########
	#Homely
	if = {
		limit = { 
			root = {
				has_trait = beauty_bad_1
			}
		}
		subtract = {
			#desc = favor_subtraction_homely
			value = 6
		}
	}
	#Ugly
	if = {
		limit = { 
			root = {
				has_trait = beauty_bad_2
			}
		}
		subtract = {
			#desc = favor_subtraction_ugly
			value = 8
		}
	}
	#Horrendous
	if = {
		limit = { 
			root = {
				has_trait = beauty_bad_3
			}
		}
		subtract = {
			#desc = favor_subtraction_horrendous
			value = 10
		}
	}

	#########Beautiful rival consorts#########
	#Comely
	if = {
		limit = { 
			root = {
				has_variable = favor
				var:favor >= neutral_consort_lower_limit
			}
			scope:harem_liege = {
				any_consort = { 
					NOT = { this = root } 
					has_trait = beauty_good_1
					age <= 45
				}
			}
		}
		subtract = {
			#desc = favor_subtraction_comely
			value = 4
		}
	}
	#Handsome
	if = {
		limit = { 
			root = {
				has_variable = favor
				var:favor >= favorite_consort_lower_limit
			}
			scope:harem_liege = {
				any_consort = { 
					NOT = { this = root } 
					has_trait = beauty_good_2
					age <= 45
				}
			}
		}
		subtract = {
			#desc = favor_subtraction_handsome
			value = 6
		}
	}
	#Beautiful
	if = {
		limit = { 
			root = {
				has_variable = favor
				var:favor >= favorite_consort_lower_limit
			}
			scope:harem_liege = {
				any_consort = { 
					NOT = { this = root } 
					has_trait = beauty_good_3
					age <= 45
				}
			}
		}
		subtract = {
			#desc = favor_subtraction_beautiful
			value = 8
		}
	}

	#########Intelligent rival consorts#########
	#Quick
	if = {
		limit = { 
			root = {
				has_variable = favor
				var:favor >= neutral_consort_lower_limit
			}
			scope:harem_liege = {
				any_consort = { 
					NOT = { this = root } 
					has_trait = intellect_good_1
				}
			}
		}
		subtract = {
			#desc = favor_subtraction_quick
			value = 3
		}
	}
	#Intelligent
	if = {
		limit = { 
			root = {
				has_variable = favor
				var:favor >= favorite_consort_lower_limit
			}
			scope:harem_liege = {
				any_consort = { 
					NOT = { this = root } 
					has_trait = intellect_good_2
				}
			}
		}
		subtract = {
			#desc = favor_subtraction_intelligent
			value = 4
		}
	}
	#Genius
	if = {
		limit = { 
			root = {
				has_variable = favor
				var:favor >= favorite_consort_lower_limit
			}
			scope:harem_liege = {
				any_consort = { 
					NOT = { this = root } 
					has_trait = intellect_good_3
				}
			}
		}
		subtract = {
			#desc = favor_subtraction_genius
			value = 5
		}
	}

	#########Rival consorts with good genetics#########
	if = {
		limit = { 
			root = {
				has_variable = favor
				var:favor >= neutral_consort_lower_limit
			}
			scope:harem_liege = {
				any_consort = { 
					NOT = { this = root } 
					num_of_good_genetic_traits > 0
				}
			}
		}
		subtract = {
			#desc = favor_subtraction_rival_genetics
			value = {
				value = 2
				if = {
					limit = { 
						root = {
							has_variable = favor
							var:favor >= favorite_consort_lower_limit
						}
						scope:harem_liege = {
							any_consort = { 
								NOT = { this = root } 
								num_of_good_genetic_traits > 1
							}
						}
					}
					add = 1
				}
			}
		}
	}

	#########Intelligence and physique#########
	#Slow
	if = {
		limit = { 
			root = {  
				has_trait = intellect_bad_1
			}
		}
		subtract = {
			#desc = favor_subtraction_slow
			value = 4
		}
	}
	#Stupid
	if = {
		limit = { 
			root = {  
				has_trait = intellect_bad_2
			}
		}
		subtract = {
			#desc = favor_subtraction_stupid
			value = 5
		}
	}
	#Imbecile
	if = {
		limit = { 
			root = {  
				has_trait = intellect_bad_3
			}
		}
		subtract = {
			#desc = favor_subtraction_imbecile
			value = 6
		}
	}

	#Delicate
	if = {
		limit = { 
			root = {  
				has_trait = physique_bad_1
			}
		}
		subtract = {
			#desc = favor_subtraction_delicate
			value = 3
		}
	}
	#Frail
	if = {
		limit = { 
			root = {  
				has_trait = physique_bad_2
			}
		}
		subtract = {
			#desc = favor_subtraction_frail
			value = 4
		}
	}
	#Feeble
	if = {
		limit = { 
			root = {  
				has_trait = physique_bad_3
			}
		}
		subtract = {
			#desc = favor_subtraction_feeble
			value = 5
		}
	}

	#########Diplomacy#########
	if = {
		limit = { 
			root = {
				diplomacy < 7
			}
		}
		subtract = {
			#desc = favor_diplomacy
			value = {
				value = 4
				if = {
					limit = { 
						root = {
							diplomacy < 3
						}
					}
					add = 2
				}
			}
		}
	}

	#########Rival consorts' diplomacy#########
	if = {
		limit = { 
			root = {
				has_variable = favor
				var:favor >= neutral_consort_lower_limit
			}
			scope:harem_liege = {
				any_consort = { 
					NOT = { this = root } 
					diplomacy >= 12
				}
			}
		}
		subtract = {
			#desc = favor_diplomacy
			value = {
				value = 2
				if = {
					limit = { 
						root = {
							has_variable = favor
							var:favor >= favorite_consort_lower_limit
						}
						scope:harem_liege = {
							any_consort = { 
								NOT = { this = root } 
								diplomacy >= 15
							}
						}
					}
					add = 2
				}
				if = {
					limit = { 
						root = {
							has_variable = favor
							var:favor >= favorite_consort_lower_limit
						}
						scope:harem_liege = {
							any_consort = { 
								NOT = { this = root } 
								diplomacy >= 17
							}
						}
					}
					add = 2
				}
			}
		}
	}
	
	#########Competition#########
	#Number of consorts
	if = {
		limit = { 
			scope:harem_liege = { 
				any_consort = { 
					is_valid_for_favor_system_trigger = { HAREM_LIEGE = scope:harem_liege }
					count >= 7
				}
			}
		}
		subtract = {
			#desc = favor_subtraction_many_consorts
			value = {
				value = 2
				if = {
					limit = {
						scope:harem_liege = {
							any_consort = { 
								is_valid_for_favor_system_trigger = { HAREM_LIEGE = scope:harem_liege }
								count >= 9
							}
						}
					}
					add = 2
				}
			}
		}
	}
	#New consorts
	if = {
		limit = { 
			root = {
				NOT = { 
					has_character_flag = flag_new_consort
				}
			}
			scope:harem_liege = { 
				any_consort = { 
					is_valid_for_favor_system_trigger = { HAREM_LIEGE = scope:harem_liege }
					is_imprisoned = no
					has_character_flag = flag_new_consort
					count >= 1
				}
			}
		}
		subtract = {
			#desc = favor_subtraction_new_consorts
			value = {
				value = 2
				if = {
					limit = { 
						scope:harem_liege = { 
							any_consort = { 
								is_valid_for_favor_system_trigger = { HAREM_LIEGE = scope:harem_liege }
								is_imprisoned = no
								has_character_flag = flag_new_consort
								count >= 2
							}
						}
					}
					add = 1
				}
				if = {
					limit = { 
						scope:harem_liege = { 
							any_consort = { 
								is_valid_for_favor_system_trigger = { HAREM_LIEGE = scope:harem_liege }
								is_imprisoned = no
								has_character_flag = flag_new_consort
								count >= 3
							}
						}
					}
					add = 1
				}
			}
		}
	}
	#Pregnant consorts
	if = { 
		limit = { 
			root = {
				NOT = { 
					has_trait = pregnant
				}
			}
			scope:harem_liege = { 
				any_consort = { 
					is_valid_for_favor_system_trigger = { HAREM_LIEGE = scope:harem_liege }
					has_trait = pregnant
					pregnancy_assumed_father ?= {
						this = scope:harem_liege
					}
					count >= 1
				}
			}
		}
		subtract = {
			#desc = favor_subtraction_pregnant_consorts
			value = {
				value = 2
				if = {
					limit = { 
						scope:harem_liege = { 
							any_consort = { 
								is_valid_for_favor_system_trigger = { HAREM_LIEGE = scope:harem_liege }
								has_trait = pregnant
								pregnancy_assumed_father ?= {
									this = scope:harem_liege
								}
								count >= 2
							}
						}
					}
					add = 2
				}
				if = {
					limit = { 
						scope:harem_liege = { 
							any_child = { 
								is_alive = yes
								count <= 3
							}
						}
					}
					add = 2
					if = {
						limit = {
							scope:harem_liege = { 
								any_child = { 
									is_alive = yes
									count = 0
								}
							}
						}
						add = 2
					}
				}
			}
		}
	}
	#########Favored consorts#########
	if = { 
		limit = { 
			scope:harem_liege = {
				any_consort = {
					NOT = { this = root }
					OR = {
						has_character_modifier = beloved_consort_modifier
						has_character_modifier = favored_consort_modifier
						has_character_modifier = favor_boost_modifier
						has_relation_soulmate = scope:harem_liege
						has_relation_lover = scope:harem_liege
					}
				}
			}
			root = {
				has_variable = favor
				var:favor >= neutral_consort_lower_limit
			}
		}
		subtract = {
			#desc = favor_subtraction_favored_consorts
			value = {
				value = 4
				#Favorites' effects on each other
				if = { #If root is a favorite, they will be more affected
					limit = { 
						root = {
							OR = {
								has_character_modifier = favored_consort_modifier
								has_character_modifier = favor_boost_modifier
								has_relation_lover = scope:harem_liege
							}
						}
					}
					add = 4
					if = { #If liege has less than 7 consorts and 2 favorites, they will be even more penalized
						limit = { 
							scope:harem_liege = {
								any_consort = {
									is_valid_for_favor_system_trigger = { HAREM_LIEGE = scope:harem_liege }
									count <= 6
								}
								any_consort = {
									OR = {
										has_character_modifier = favored_consort_modifier
										has_character_modifier = favor_boost_modifier
										has_relation_lover = scope:harem_liege
									}
									count >= 2
								}
							}
						}
						add = 6
					}
					if = { #There can only be a max of 2 favorites
						limit = { 
							scope:harem_liege = {
								any_consort = {
									OR = {
										has_character_modifier = favored_consort_modifier
										has_character_modifier = favor_boost_modifier
										has_relation_lover = scope:harem_liege
									}
									count >= 3
								}
							}
						}
						add = 12
					}
					if = { #There can only be a max of 2 favorites
						limit = { 
							scope:harem_liege = {
								any_consort = {
									OR = {
										has_character_modifier = favored_consort_modifier
										has_character_modifier = favor_boost_modifier
										has_relation_lover = scope:harem_liege
									}
									count >= 4
								}
							}
						}
						add = 24
					}
					if = { #There can only be a max of 2 favorites
						limit = { 
							scope:harem_liege = {
								any_consort = {
									OR = {
										has_character_modifier = favored_consort_modifier
										has_character_modifier = favor_boost_modifier
										has_relation_lover = scope:harem_liege
									}
									count >= 5
								}
							}
						}
						add = 48
					}
				}
				#Beloved effects on each other
				if = { #Beloved consorts will take more favor from everyone
					limit = { 
						scope:harem_liege = {
							any_consort = {
								NOT = { this = root }
								OR = {
									has_character_modifier = beloved_consort_modifier
									has_relation_soulmate = scope:harem_liege
								}
								count >= 1
							}
						}
					}
					add = 2
					if = { #More if root is favored
						limit = { 
							root = {
								OR = {
									has_character_modifier = favored_consort_modifier
									has_character_modifier = favor_boost_modifier
									has_relation_lover = scope:harem_liege
								}
							}
						}
						add = 4
					}
					if = { #There can only be one beloved consort
						limit = { 
							root = {
								OR = {
									has_character_modifier = beloved_consort_modifier
									has_relation_soulmate = scope:harem_liege
								}
							}
						}
						add = 20
						if = { #There can only be one beloved consort
							limit = { 
								scope:harem_liege = {
									any_consort = {
										NOT = { this = root }
										OR = {
											has_character_modifier = beloved_consort_modifier
											has_relation_soulmate = scope:harem_liege
										}
										count >= 2
									}
								}
							}
							add = 40
						}
						if = { #There can only be one beloved consort
							limit = { 
								scope:harem_liege = {
									any_consort = {
										NOT = { this = root }
										OR = {
											has_character_modifier = beloved_consort_modifier
											has_relation_soulmate = scope:harem_liege
										}
										count >= 3
									}
								}
							}
							add = 80
						}
						if = { #There can only be one beloved consort
							limit = { 
								scope:harem_liege = {
									any_consort = {
										NOT = { this = root }
										OR = {
											has_character_modifier = beloved_consort_modifier
											has_relation_soulmate = scope:harem_liege
										}
										count >= 4
									}
								}
							}
							add = 160
						}
					}
				}
			}

		}
	}

	#########Ageism#########
	if = {
		limit = { 
			root = {
				age >= 27
			}
		}
		subtract = {
			#desc = favor_subtraction_age
			value = {
				value = 2
				if = {
					limit = { 
						root = {
							age >= 37
						}
					}
					add = 1
				}
				if = {
					limit = { 
						root = {
							age >= 45
						}
					}
					add = 2
				}
				if = {
					limit = { 
						root = {
							age >= 50
						}
					}
					add = 1
				}
				if = {
					limit = { 
						scope:harem_liege = {
							any_consort = {
								NOT = { this = root }
								is_valid_for_favor_system_trigger = { HAREM_LIEGE = scope:harem_liege }
								age <= 23
								count >= 1
							}
						}
					}
					add = 1
				}
				if = {
					limit = { 
						scope:harem_liege = {
							any_consort = {
								NOT = { this = root }
								is_valid_for_favor_system_trigger = { HAREM_LIEGE = scope:harem_liege }
								age <= 23
								count >= 3
							}
						}
					}
					add = 1
				}
			}
		}
	}

	#########Unfavored children#########
	if = {
		limit = { 
			root = {
				any_child = { 
					is_child_of = scope:harem_liege
					is_alive = yes
					OR = {	
						has_relation_rival = scope:harem_liege
						has_relation_nemesis = scope:harem_liege
					}
					count > 0
				}
			}
		}
		subtract = {
			#desc = favor_subtraction_unfriendly_children
			value = {
				value = 4
				if = {
					limit = { 
						root = {
							any_child = { 
								is_child_of = scope:harem_liege
								is_alive = yes
								has_relation_rival = scope:harem_liege
								count >= 2
							}
						}
					}
					add = 2
				}
				if = {
					limit = { 
						root = {
							any_child = { 
								is_child_of = scope:harem_liege
								is_alive = yes
								has_relation_nemesis = scope:harem_liege
								count >= 1
							}
						}
					}
					add = 4
				}
			}
		}
	}

	#########Arrested#########
	if = {
		limit = { 
			root = {
				is_imprisoned_by = scope:harem_liege
				OR = { 
					is_in_prison_type = house_arrest
					is_in_prison_type = dungeon
				}
			}
		}
		subtract = {
			#desc = favor_subtraction_arrest
			value = {
				value = 12
				if = {
					limit = { 
						root = {
							is_in_prison_type = dungeon
						}
					}
					add = 12
				}
			}
		}
	}

	#########Modifiers#########
	if = { #... for the one who has not, even what he has will be taken away
		limit = { 
			root = {
				has_character_modifier = forgotten_consort_modifier
			}
		}
		subtract = { #Half a month
			#desc = favor_subtraction_forgotten
			value = 4
		}
	}
	else_if = { #... for the one who has not, even what he has will be taken away
		limit = { 
			root = {
				has_character_modifier = unfavored_consort_modifier
			}
		}
		subtract = { #1/4 month
			#desc = favor_subtraction_unfavored
			value = 2
		}
	}
	if = { # Bed services are the main way to gain favor
		limit = { 
			root = {
				has_character_modifier = rejected_from_marriage_bed_modifier
			}
		}
		subtract = { #1 month
			#desc = favor_subtraction_rejected_from_bed
			value = 8
		}
	}

	#########Traits#########
	#root traits
	if = { #Craven
		limit = { 
			root = {
				has_trait = craven
			}
			scope:harem_liege = {
				NOR = {
					has_trait = shy
					has_trait = craven
				}
			}
		}
		subtract = {
			#desc = favor_subtraction_craven
			value = 2
		}
	}
	if = { #Brave
		limit = { 
			root = {
				has_trait = brave
			}
			scope:harem_liege = {
				OR = {
					has_trait = shy
					has_trait = craven
				}
			}
		}
		subtract = {
			#desc = favor_subtraction_brave
			value = 2
		}
	}
	if = { #Wrathful
		limit = { 
			root = {
				has_trait = wrathful
			}
		}
		subtract = {
			#desc = favor_subtraction_wrathful
			value = {
				value = 2
				if = {
					limit = { 
						scope:harem_liege = {
							has_trait = wrathful
						}
					}
					add = 1
				}
				if = {
					limit = { 
						scope:harem_liege = {
							has_trait = calm
						}
					}
					add = 1
				}
			}
		}
	}
	if = { #Chaste
		limit = { 
			root = {
				has_trait = chaste
			}
			scope:harem_liege = {
				NOT = {
					has_trait = chaste
				}
			}
		}
		subtract = {
			#desc = favor_subtraction_chaste
			value = {
				value = 2
				if = {
					limit = { 
						scope:harem_liege = {
							has_trait = lustful
						}
					}
					add = 1
				}
			}
		}
	}
	if = { #Lustful
		limit = { 
			root = {
				has_trait = lustful
			}
			scope:harem_liege = {
				has_trait = chaste
			}
		}
		subtract = {
			#desc = favor_subtraction_lustful
			value = 2
		}
	}
	if = { #Ambitious
		limit = { 
			root = {
				has_trait = ambitious
			}
			scope:harem_liege = {
				OR ={
					has_trait = content
					has_trait = generous
				}
			}
		}
		subtract = {
			#desc = favor_subtraction_ambitious
			value = {
				value = 2
				if = {
					limit = { 
						scope:harem_liege = {
							has_trait = content
						}
					}
					add = 2
				}
			}
		}
	}
	if = { #Lazy
		limit = { 
			root = {
				has_trait = lazy
			}
			scope:harem_liege = {
				NOT = {
					has_trait = content
				}
			}
		}
		subtract = {
			#desc = favor_subtraction_lazy
			value = {
				value = 2
				if = { #Extra if root is married
					limit = { 
						root = {
							is_married = yes
							NOR = {
								has_court_position = grand_consort_court_position
								AND = {
									exists = scope:harem_liege.primary_spouse
									this = scope:harem_liege.primary_spouse
								}
							}
						}
					}
					add = 1
				}
				if = { #Extra if root the GC
					limit = { 
						root = {
							has_court_position = grand_consort_court_position
						}
					}
					add = 2
				}
				if = { #Extra if root is the PS
					limit = { 
						exists = scope:harem_liege.primary_spouse
						root = {
							this = scope:harem_liege.primary_spouse
						}
					}
					add = 4
				}
			}
		}
	}
	if = { #Vengeful
		limit = { 
			root = {
				has_trait = vengeful
			}
			scope:harem_liege = {
				OR = {	
					has_trait = forgiving
					has_trait = compassionate
				}
				NOT = {
					has_trait = vengeful
				}
			}
		}
		subtract = {
			#desc = favor_subtraction_vengeful
			value = 2
		}
	}
	if = { #Greedy
		limit = { 
			root = {
				has_trait = greedy
			}
		}
		subtract = {
			#desc = favor_subtraction_greedy
			value = {
				value = 1
				if = { 
					limit = { 
						scope:harem_liege = {
							has_trait = generous
						}
					}
					add = 1
				}
			}
		}
	}

	if = { #Shy
		limit = { 
			root = {
				has_trait = shy
			}
		}
		subtract = {
			#desc = favor_subtraction_shy
			value = 2
			if = {
				limit = {
					scope:harem_liege = {
						has_trait = gregarious
					}
				}
				add = 1
			}
		}
	}
	if = { #Gregarious
		limit = { 
			root = {
				has_trait = gregarious
			}
			scope:harem_liege = {
				has_trait = shy
			}
		}
		subtract = {
			#desc = favor_subtraction_gregarious
			value = 2
		}
	}

	if = { #Deceitful
		limit = { 
			root = {
				has_trait = deceitful
			}
			scope:harem_liege = {
				has_trait = honest
			}
		}
		subtract = {
			#desc = favor_subtraction_deceitful
			value = 2
		}
	}

	if = { #Arrogant
		limit = { 
			root = {
				has_trait = arrogant
			}
			scope:harem_liege = {
				has_trait = humble
			}
		}
		subtract = {
			#desc = favor_subtraction_arrogant
			value = 2
		}
	}
	
	if = { #Arbitrary
		limit = { 
			root = {
				has_trait = arbitrary
			}
			scope:harem_liege = {
				has_trait = just
			}
		}
		subtract = {
			#desc = favor_subtraction_arbitrary
			value = 2
		}
	}
	if = { #Just
		limit = { 
			root = {
				has_trait = just
			}
			scope:harem_liege = {
				has_trait = arbitrary
			}
		}
		subtract = {
			#desc = favor_subtraction_just
			value = 2
		}
	}

	if = { #Patient
		limit = { 
			root = {
				has_trait = patient
			}
			scope:harem_liege = {
				has_trait = impatient
			}
		}
		subtract = {
			#desc = favor_subtraction_patient
			value = 2
		}
	}
	if = { #Impatient
		limit = { 
			root = {
				has_trait = impatient
			}
			scope:harem_liege = {
				has_trait = patient
			}
		}
		subtract = {
			#desc = favor_subtraction_impatient
			value = 2
		}
	}
	if = { #Gluttonous
		limit = { 
			root = {
				has_trait = gluttonous
			}
			scope:harem_liege = {
				OR = {
					NOT = { has_trait = gluttonous }
					AND = {
						has_trait = gluttonous
						has_trait = arbitrary
					}
				}
			}
		}
		subtract = {
			#desc = favor_subtraction_gluttonous
			value = {
				value = 1
				if = {
					limit = {
						root = {
							has_trait = temperate
						}
					}
					add = 1
				}
			}
		}
	}

	if = { #Zealous
		limit = { 
			root = {
				has_trait = zealous
			}
			scope:harem_liege = {
				has_trait = cynical
			}
		}
		subtract = {
			#desc = favor_subtraction_zealous
			value = 2
		}
	}
	if = { #Callous
		limit = { 
			root = {
				has_trait = callous
			}
			scope:harem_liege = {
				OR = {	
					has_trait = forgiving
					has_trait = compassionate
				}
			}
		}
		subtract = {
			#desc = favor_subtraction_callous
			value = 2
		}
	}
	if = { #Sadistic
		limit = { 
			root = {
				has_trait = sadistic
			}
			scope:harem_liege = {
				OR = {	
					has_trait = forgiving
					has_trait = compassionate
				}
			}
		}
		subtract = 2
	}

	if = { #Fickle
		limit = { 
			root = {
				has_trait = fickle
			}
			scope:harem_liege = {
				has_trait = stubborn
			}
		}
		subtract = {
			#desc = favor_subtraction_fickle
			value = 2
		}
	}
	if = { #Stubborn
		limit = { 
			root = {
				has_trait = stubborn
			}
			scope:harem_liege = {
				has_trait = fickle
			}
		}
		subtract = {
			#desc = favor_subtraction_stubborn
			value = 2
		}
	}
	if = { #Eccentric
		limit = { 
			root = {
				has_trait = eccentric
			}
			scope:harem_liege = {
				has_trait = stubborn
			}
		}
		subtract = {
			#desc = favor_subtraction_eccentric
			value = 2
		}
	}

	if = { #Reclusive
		limit = { 
			root = {
				has_trait = reclusive
			}
		}
		subtract = 4
	}
	if = { #Wounded
		limit = { 
			root = {
				has_trait = wounded
			}
		}
		subtract = {
			#desc = favor_subtraction_wounded
			value = {
				value = 2
				if = {
					limit = { 
						root = {
							has_trait = wounded_2
						}
					}
					add = 1
				}
				if = {
					limit = { 
						root = {
							has_trait = wounded_3
						}
					}
					add = 2
				}
			}
		}
	}
	if = { #Bad genetics
		limit = { 
			root = {
				num_of_bad_genetic_traits > 0
			}
		}
		subtract = {
			#desc = favor_subtraction_bad_genetics
			value = {
				value = 6
				if = {
					limit = { 
						root = {
							num_of_bad_genetic_traits > 1
						}
					}
					add = 4
				}
			}
		}
	}
	if = { #Bad health
		limit = { 
			root = {
				OR = {
					has_trait = lunatic_1
					has_trait = possessed_1
					has_trait = one_eyed
					has_trait = one_legged
					has_trait = disfigured
					has_trait = eunuch
					has_trait = sickly
					has_trait = infirm
					has_trait = incapable
					has_trait = maimed
					has_trait = blind
					has_trait = ill
					has_trait = bubonic_plague
					has_trait = cancer
					has_trait = consumption
					has_trait = great_pox
					has_trait = gout_ridden
					has_trait = leper
					has_trait = lovers_pox
					has_trait = pneumonic
					has_trait = smallpox
					has_trait = typhus
					has_trait = dysentery
					has_trait = ergotism
					has_trait = measles
				}
			}
		}
		subtract = {
			#desc = favor_subtraction_bad_traits
			value = {
				value = 3
				if = { #lunatic_1
					limit = { 
						root = {
							has_trait = lunatic_1
						}
					}
					add = 2
				}
				if = { #possessed_1
					limit = { 
						root = {
							has_trait = possessed_1
						}
					}
					add = 2
				}
				if = { #one_legged
					limit = { 
						root = {
							has_trait = one_legged
						}
					}
					add = 2
				}
				if = { #disfigured
					limit = { 
						root = {
							has_trait = disfigured
						}
					}
					add = 4
				}
				if = { #maimed
					limit = { 
						root = {
							has_trait = maimed
						}
					}
					add = 4
				}
				if = { #blind
					limit = { 
						root = {
							has_trait = blind
						}
					}
					add = 2
				}
				if = { #bubonic_plague
					limit = { 
						root = {
							has_trait = bubonic_plague
						}
					}
					add = 8
				}
				if = { #consumption
					limit = { 
						root = {
							has_trait = consumption
						}
					}
					add = 2
				}
				if = { #great_pox
					limit = { 
						root = {
							has_trait = great_pox
						}
					}
					add = 8
				}
				if = { #gout_ridden
					limit = { 
						root = {
							has_trait = gout_ridden
						}
					}
					add = 3
				}
				if = { #leper
					limit = { 
						root = {
							has_trait = leper
						}
					}
					add = 8
				}
				if = { #lovers_pox
					limit = { 
						root = {
							has_trait = lovers_pox
						}
					}
					add = 4
				}
				if = { #smallpox
					limit = { 
						root = {
							has_trait = smallpox
						}
					}
					add = 6
				}
				if = { #typhus
					limit = { 
						root = {
							has_trait = typhus
						}
					}
					add = 6
				}
				if = { #dysentery
					limit = { 
						root = {
							has_trait = dysentery
						}
					}
					add = 6
				}
				if = { #ergotism
					limit = { 
						root = {
							has_trait = ergotism
						}
					}
					add = 4
				}
				if = { #measles
					limit = { 
						root = {
							has_trait = measles
						}
					}
					add = 4
				}
				if = { #Incapable
					limit = { 
						root = {
							has_trait = incapable
						}
					}
					add = 10
				}
				if = { #Eunuch
					limit = { 
						root = {
							has_trait = eunuch
						}
					}
					add = 6
				}
			}
		}
	}

	if = { #Drunkard
		limit = { 
			root = {
				has_trait = drunkard
			}
			scope:harem_liege = {
				OR = {
					NOT = {	
						has_trait = drunkard
					}
					AND = {	
						has_trait = drunkard
						has_trait = arbitrary
					}
				}
			}
		}
		subtract = 2
	}
	if = { #Flagellant
		limit = { 
			root = {
				has_trait = flagellant
			}
			scope:harem_liege = {
				OR = {
					NOT = {	
						has_trait = flagellant
					}
					AND = {
						has_trait = flagellant
						has_trait = arbitrary
					}
				}
			}
		}
		subtract = 2
	}
	if = { #Comfort_eater
		limit = { 
			root = {
				has_trait = comfort_eater
			}
			scope:harem_liege = {
				OR = {
					NAND = {	
						has_trait = comfort_eater
						has_trait = gluttonous
					}
					AND = {	
						OR = {
							has_trait = comfort_eater
							has_trait = gluttonous
						}
						has_trait = arbitrary
					}
				}
			}
		}
		subtract = 2
	}
	if = { #Contrite
		limit = { 
			root = {
				has_trait = contrite
			}
			scope:harem_liege = {
				OR = {
					NOT = {	
						has_trait = contrite
					}
					AND = {
						has_trait = contrite
						has_trait = arbitrary
					}
				}
			}
		}
		subtract = 2
	}
	if = { #Improvident
		limit = { 
			root = {
				has_trait = improvident
			}
			scope:harem_liege = {
				has_trait = greedy
			}
		}
		subtract = 2
	}
	if = { #Inappetetic
		limit = { 
			root = {
				has_trait = inappetetic
			}
			scope:harem_liege = {
				OR = {
					NOT = {	
						has_trait = inappetetic
					}
					AND = {
						has_trait = inappetetic
						has_trait = arbitrary
					}
				}
			}
		}
		subtract = 2
	}
	if = { #Irritable
		limit = { 
			root = {
				has_trait = irritable
			}
		}
		subtract = 4
	}
	if = { #Rakish
		limit = { 
			root = {
				has_trait = rakish
			}
		}
		subtract = {
			value = {
				value = 4
				if = {
					limit = {
						scope:harem_liege = {
							has_trait = chaste
						}
					}
					add = 2
				}
			}
		}
	}
	if = { #Hashishiyah
		limit = { 
			root = {
				has_trait = hashishiyah
			}
			scope:harem_liege = {
				OR = {
					NOT = {	
						has_trait = hashishiyah
					}
					AND = {
						has_trait = hashishiyah
						has_trait = arbitrary
					}
				}
			}
		}
		subtract = 2
	}
	if = { #Profligate
		limit = { 
			root = {
				has_trait = profligate
			}
			scope:harem_liege = {
				OR = {
					NOT = {	
						has_trait = profligate
					}
					AND = {
						has_trait = profligate
						has_trait = arbitrary
					}
				}
			}
		}
		subtract = {
			value = {
				value = 2
				if = {
					limit = {
						scope:harem_liege = {
							has_trait = greedy
						}
					}
					add = 2
				}
			}
		}
	}

	#Harem_liege traits#
	if = { #Bad health
		limit = { 
			scope:harem_liege = {
				OR = {
					has_trait = lunatic_1
					has_trait = possessed_1
					has_trait = disfigured
					has_trait = eunuch
					has_trait = sickly
					has_trait = infirm
					has_trait = incapable
					has_trait = maimed
					has_trait = blind
					has_trait = ill
					has_trait = bubonic_plague
					has_trait = cancer
					has_trait = consumption
					has_trait = great_pox
					has_trait = gout_ridden
					has_trait = leper
					has_trait = lovers_pox
					has_trait = pneumonic
					has_trait = smallpox
					has_trait = typhus
					has_trait = dysentery
					has_trait = ergotism
					has_trait = measles
				}
			}
		}
		subtract = {
			#desc = favor_subtraction_bad_traits
			value = {
				value = 2
				if = { #lunatic_1
					limit = { 
						scope:harem_liege = {
							has_trait = lunatic_1
						}
					}
					add = 1
				}
				if = { #possessed_1
					limit = { 
						scope:harem_liege = {
							has_trait = possessed_1
						}
					}
					add = 1
				}
				if = { #maimed
					limit = { 
						scope:harem_liege = {
							has_trait = maimed
						}
					}
					add = 2
				}
				if = { #blind
					limit = { 
						scope:harem_liege = {
							has_trait = blind
						}
					}
					add = 2
				}
				if = { #bubonic_plague
					limit = { 
						scope:harem_liege = {
							has_trait = bubonic_plague
						}
					}
					add = 4
				}
				if = { #consumption
					limit = { 
						scope:harem_liege = {
							has_trait = consumption
						}
					}
					add = 1
				}
				if = { #great_pox
					limit = { 
						scope:harem_liege = {
							has_trait = great_pox
						}
					}
					add = 4
				}
				if = { #gout_ridden
					limit = { 
						scope:harem_liege = {
							has_trait = gout_ridden
						}
					}
					add = 2
				}
				if = { #leper
					limit = { 
						scope:harem_liege = {
							has_trait = leper
						}
					}
					add = 4
				}
				if = { #lovers_pox
					limit = { 
						scope:harem_liege = {
							has_trait = lovers_pox
						}
					}
					add = 1
				}
				if = { #smallpox
					limit = { 
						scope:harem_liege = {
							has_trait = smallpox
						}
					}
					add = 2
				}
				if = { #typhus
					limit = { 
						scope:harem_liege = {
							has_trait = typhus
						}
					}
					add = 3
				}
				if = { #dysentery
					limit = { 
						scope:harem_liege = {
							has_trait = dysentery
						}
					}
					add = 3
				}
				if = { #ergotism
					limit = { 
						scope:harem_liege = {
							has_trait = ergotism
						}
					}
					add = 2
				}
				if = { #measles
					limit = { 
						scope:harem_liege = {
							has_trait = measles
						}
					}
					add = 2
				}
				if = { #Incapable
					limit = { 
						scope:harem_liege = {
							has_trait = incapable
						}
					}
					add = 8
				}
				if = { #Eunuch
					limit = { 
						scope:harem_liege = {
							has_trait = eunuch
						}
					}
					add = 3
				}
			}
		}
	}

	if = { #Zealous
		limit = { 
			root = {
				has_trait = cynical
			}
			scope:harem_liege = {
				has_trait = zealous
			}
		}
		subtract = {
			#desc = favor_subtraction_cynical
			value = 2
		}
	}
	if = { #Infidel
		limit = { 
			scope:harem_liege = {
				OR = {
					AND = {
						has_trait = zealous
						faith = {
							faith_hostility_level = {
								target = root.faith
								value >= faith_astray_level
							}
						}
					}
					AND = {
						NOT = { has_trait = cynical }
						faith = {
							faith_hostility_level = {
								target = root.faith
								value >= faith_hostile_level
							}
						}
					}
				}
			}
		}
		subtract = {
			#desc = favor_subtraction_infidel
			value = 4
		}
	}

	#########Cultural acceptance#########
	if = { #Foreigner
		limit = { 
			scope:harem_liege = {
				culture = {
					cultural_acceptance = { target = root.culture value < 50 }
				}
				NOR = {
					has_trait = compassionate
					has_trait = forgiving
					has_trait = eccentric
					has_trait = scholar
				}
			}
		}
		subtract = {
			#desc = favor_subtraction_foreigner
			value = {
				value = 1
				if = {
					limit = {
						scope:harem_liege.culture = {
							cultural_acceptance = { target = root.culture value < 26 }
						}
					}
					add = 1
				}
				if = {
					limit = {
						scope:harem_liege.culture = {
							cultural_acceptance = { target = root.culture value < 11 }
						}
					}
					add = 1
				}
				if = {
					limit = {
						scope:harem_liege = {
							has_trait = paranoid
						}
					}
					add = 1
				}
			}
		}
	}

	#########Travel#########
	#If you're able to travel and harem liege traveled without you, you're unfavored
	if = {
		limit = { 
			scope:harem_liege = {
				is_travelling = yes
				any_consort = {
					is_travelling = yes
					current_travel_plan ={
						travel_plan_owner = scope:harem_liege
					}
					count > 0
				}
			}
			root = {
				is_travelling = no
				is_diarch = no
				NOR = {
					has_trait = pregnant
					has_trait = ill
					has_trait = wounded
					has_trait = infirm
					has_trait = incapable
					has_trait = maimed
					has_trait = blind
					has_trait = bubonic_plague
					has_trait = cancer
					has_trait = consumption
					has_trait = great_pox
					has_trait = gout_ridden
					has_trait = leper
					has_trait = lovers_pox
					has_trait = pneumonic
					has_trait = smallpox
					has_trait = typhus
					has_trait = dysentery
					has_trait = ergotism
					has_trait = measles
				}
				age <= 50
			}
		}
		subtract = {
			#desc = favor_subtraction_uninvited_consort
			value = 2
		}
	}

	#########Balancing favor#########
	if = {
		limit = {
			scope:harem_liege = {
				any_court_position_holder = {
					type = grand_consort_court_position
					aptitude:grand_consort_court_position >= 3
					has_character_flag = gc_balancing_favor_flag
				}
			}
		}
		if = { #Subtract more to the favored ones
			limit = {
				root = {
					has_variable = favor
					var:favor = beloved_consort_upper_limit
				}
			}
			if = {
				limit = {
					scope:harem_liege = {
						any_court_position_holder = {
							type = grand_consort_court_position
							aptitude:grand_consort_court_position = 5
						}
					}
				}
				multiply = 2.2
			}
			else_if = {
				limit = {
					scope:harem_liege = {
						any_court_position_holder = {
							type = grand_consort_court_position
							aptitude:grand_consort_court_position = 4
						}
					}
				}
				multiply = 2.1
			}
			else = {
				multiply = 2
			}
		}
		else_if = { #Subtract more to the favored ones
			limit = {
				root = {
					has_variable = favor
					var:favor >= beloved_consort_lower_limit
				}
			}
			if = {
				limit = {
					scope:harem_liege = {
						any_court_position_holder = {
							type = grand_consort_court_position
							aptitude:grand_consort_court_position = 5
						}
					}
				}
				multiply = 2
			}
			else_if = {
				limit = {
					scope:harem_liege = {
						any_court_position_holder = {
							type = grand_consort_court_position
							aptitude:grand_consort_court_position = 4
						}
					}
				}
				multiply = 1.9
			}
			else = {
				multiply = 1.8
			}
		}
		else_if = { #Subtract more to the favored ones
			limit = {
				root = {
					has_variable = favor
					var:favor >= favorite_consort_lower_limit
				}
			}
			if = {
				limit = {
					scope:harem_liege = {
						any_court_position_holder = {
							type = grand_consort_court_position
							aptitude:grand_consort_court_position = 5
						}
					}
				}
				multiply = 1.8
			}
			else_if = {
				limit = {
					scope:harem_liege = {
						any_court_position_holder = {
							type = grand_consort_court_position
							aptitude:grand_consort_court_position = 4
						}
					}
				}
				multiply = 1.65
			}
			else = {
				multiply = 1.5
			}
		}
		else_if = { #Add less to high-neutral ones
			limit = {
				root = {
					has_variable = favor
					var:favor >= 482
				}
			}
			if = {
				limit = {
					scope:harem_liege = {
						any_court_position_holder = {
							type = grand_consort_court_position
							aptitude:grand_consort_court_position = 5
						}
					}
				}
				multiply = 1.15
			}
			else_if = {
				limit = {
					scope:harem_liege = {
						any_court_position_holder = {
							type = grand_consort_court_position
							aptitude:grand_consort_court_position = 4
						}
					}
				}
				multiply = 1.1
			}
			else = {
				multiply = 1.05
			}
		}
		else_if = { #Add more to the unfavored ones
			limit = {
				root = {
					has_variable = favor
					var:favor >= unfavored_consort_lower_limit
				}
			}
			if = {
				limit = {
					scope:harem_liege = {
						any_court_position_holder = {
							type = grand_consort_court_position
							aptitude:grand_consort_court_position = 5
						}
					}
				}
				multiply = 0.2
			}
			else_if = {
				limit = {
					scope:harem_liege = {
						any_court_position_holder = {
							type = grand_consort_court_position
							aptitude:grand_consort_court_position = 4
						}
					}
				}
				multiply = 0.25
			}
			else = {
				multiply = 0.3
			}
		}
		else_if = { #Add more to the unfavored ones
			limit = {
				root = {
					has_variable = favor
					var:favor >= 5
				}
			}
			if = {
				limit = {
					scope:harem_liege = {
						any_court_position_holder = {
							type = grand_consort_court_position
							aptitude:grand_consort_court_position = 5
						}
					}
				}
				multiply = 0.15
			}
			else_if = {
				limit = {
					scope:harem_liege = {
						any_court_position_holder = {
							type = grand_consort_court_position
							aptitude:grand_consort_court_position = 4
						}
					}
				}
				multiply = 0.2
			}
			else = {
				multiply = 0.25
			}
		}
		else = { #Add more to the unfavored ones
			if = {
				limit = {
					scope:harem_liege = {
						any_court_position_holder = {
							type = grand_consort_court_position
							aptitude:grand_consort_court_position = 5
						}
					}
				}
				multiply = 0
			}
			else_if = {
				limit = {
					scope:harem_liege = {
						any_court_position_holder = {
							type = grand_consort_court_position
							aptitude:grand_consort_court_position = 4
						}
					}
				}
				multiply = 0.05
			}
			else = {
				multiply = 0.1
			}
		}
	}
	if = { #Bad aptitude widens the gap
		limit = {
			scope:harem_liege = {
				any_court_position_holder = {
					type = grand_consort_court_position
					aptitude:grand_consort_court_position <= 2
					has_character_flag = gc_balancing_favor_flag
				}
			}
		}
        if = {
            limit = {
                root = {
                    NOT = { has_character_flag = gc_balancing_favor_flag }
                }
            }
            if = { # It's harder to reduce favor for favorites
                limit = {
                    root = {
                        has_variable = favor
                        var:favor >= favorite_consort_lower_limit
                    }
                }
                if = {
                    limit = {
                        scope:harem_liege = {
                            any_court_position_holder = {
                                type = grand_consort_court_position
                                aptitude:grand_consort_court_position = 2
                            }
                        }
                    }
                    multiply = 1.1
                }
                else = {
                    multiply = 1.2
                }
            }
            else_if = { # Subtract from the neutral ones
                limit = {
                    root = {
                        has_variable = favor
                        var:favor >= neutral_consort_lower_limit
                    }
                }
                if = {
                    limit = {
                        scope:harem_liege = {
                            any_court_position_holder = {
                                type = grand_consort_court_position
                                aptitude:grand_consort_court_position = 2
                            }
                        }
                    }
                    multiply = 1.15
                }
                else = {
                    multiply = 1.25
                }
            }
            else = { #Add more to the unfavored ones
                if = {
                    limit = {
                        scope:harem_liege = {
                            any_court_position_holder = {
                                type = grand_consort_court_position
                                aptitude:grand_consort_court_position = 2
                            }
                        }
                    }
                    multiply = 1.2
                }
                else = {
                    multiply = 1.3
                }
            }
        }
		else = { #The GC will add more favor to themselves
			if = {
				limit = {
					scope:harem_liege = {
						any_court_position_holder = {
							type = grand_consort_court_position
							aptitude:grand_consort_court_position = 2
						}
					}
				}
				multiply = 0.85
			}
			else = {
				multiply = 0.75
			}
		}
	}
}

# Levels of favor #
beloved_consort_upper_limit = 964
beloved_consort_lower_limit = 868
favorite_consort_upper_limit = 867
favorite_consort_lower_limit = 675
neutral_consort_upper_limit = 674
neutral_consort_lower_limit = 290
unfavored_consort_upper_limit = 289
unfavored_consort_lower_limit = 97
forgotten_consort_upper_limit = 96
forgotten_consort_lower_limit = 0

initial_favor_valuation = {
	value = 482

	####They already have a favor modifier####
	if = { #They're beloved
		limit = {
			root = {
				OR = {
					has_character_modifier = beloved_consort_modifier
					has_relation_soulmate = scope:harem_liege
					has_relation_best_friend = scope:harem_liege
				}
			}
		}
		add = 434
	}
	else_if = { #They're favored
		limit = {
			root = {
				OR = {
					has_character_modifier = favored_consort_modifier
					has_character_modifier = favor_boost_modifier
					has_relation_lover = scope:harem_liege
					has_relation_friend = scope:harem_liege
				}
			}
		}
		add = 289
	}
	else_if = { #They're unfavored
		limit = {
			root = {
				OR = {
					has_character_modifier = unfavored_consort_modifier
					has_relation_rival = scope:harem_liege
				}
			}
		}
		subtract = 289
	}
	else_if = { #They're forgotten
		limit = {
			root = {
				OR = {
					has_character_modifier = forgotten_consort_modifier
					has_relation_nemesis = scope:harem_liege
				}
			}
		}
		subtract = 434
	}
	
	####Demoted consorts####
	if = {
		limit = {
			root = {
				is_demoted_consort_trigger = yes
			}
		}
		if = { #The PS will start really low
			limit = {
				root = {
					has_character_modifier = demoted_primary_spouse_modifier
				}
			}
			subtract = 289
		}
		else = {
			subtract = 241
		}
	}

	##Additions##
	
	#########New consorts#########
	if = {
		limit = { 
			root = { 	
				has_character_flag = flag_new_consort
			}
		}
		add = {
			#desc = favor_addition_new_consort
			value = favor_miniscule_value_gain
		}
	}

	#########Youth#########
	if = {
		limit = { 
			root = { 	
				age <= 23
			}
		}
		add = {
			#desc = favor_addition_youth
			value = favor_miniscule_value_gain
		}
	}

	#########Ranking#########
	#The PS
	if = {
		limit = { 
			exists = scope:harem_liege.primary_spouse
			root = { 	
				this = scope:harem_liege.primary_spouse
			}
		}
		add = {
			#desc = favor_addition_ps
			value = favor_ps_bonus
		}
	}
	#The GC
	if = {
		limit = { 
			root = { 	
				has_court_position = grand_consort_court_position
				is_demoted_consort_trigger = no
			}
		}
		add = {
			#desc = favor_addition_gc
			value = favor_gc_bonus
		}
	}
	#Spouses
	if = {
		limit = { 
			root = { 	
				is_spouse_of = scope:harem_liege
				is_demoted_consort_trigger = no
				NOR = {
					this = scope:harem_liege.primary_spouse
					has_court_position = grand_consort_court_position
				}
			}
		}
		add = {
			#desc = favor_addition_ss
			value = favor_ss_bonus
		}
	}

	#########Children#########
	#Number of children
	if = {
		limit = {
			root = {
				any_child = {
					is_child_of = scope:harem_liege
					is_alive = yes
					count > 0
				}
			}
		}
		root = {
			every_child = {
				limit = {
					is_child_of = scope:harem_liege
					is_alive = yes
				}
				add = {
					value = favor_minor_value_gain
					if = { #Eligible heirs
						limit = {
							character_gender_can_inherit_from_trigger = { CHARACTER = scope:harem_liege }
						}
						add = favor_miniscule_value_gain
					}
					if = { #Closer to the throne
						limit = {
							scope:harem_liege.primary_title = {
								place_in_line_of_succession = {
									target = prev
									value <= 3
								}
							}
						}
						add = favor_miniscule_value_gain
					}
					if = { #Player heir
						limit = {
							is_player_heir_of = scope:harem_liege
						}
						add = favor_miniscule_value_gain
					}
					if = { #Friends with liege
						limit = {
							has_relation_friend = scope:harem_liege
						}
						add = favor_miniscule_value_gain
					}
					if = { #Friends with liege
						limit = {
							has_relation_best_friend = scope:harem_liege
						}
						add = favor_minor_value_gain
					}
				}
			}
		}
	}
	#Pregnant consorts
	if = {
		limit = { 
			root = {  
				has_trait = pregnant
				pregnancy_assumed_father ?= {
					this = scope:harem_liege
				}
			}
		}
		add = {
			#desc = favor_addition_pregnant
			value = favor_high_value_gain
			if = { #More if there are few children
				limit = { 
					scope:harem_liege = {  
						any_child = { 
							is_alive = yes
							count <= 3
						}
					}
				}
				add = favor_medium_value_gain
			}
		}
	}

	#########Beauty#########
	#Comely
	if = {
		limit = { 
			root = {  
				has_trait = beauty_good_1
				age <= 45
			}
		}
		add = {
			#desc = favor_addition_comely
			value = favor_high_value_gain
		}
	}
	#Handsome
	if = {
		limit = { 
			root = {  
				has_trait = beauty_good_2
				age <= 45
			}
		}
		add = {
			#desc = favor_addition_handsome
			value = favor_ultra_high_value_gain
			add = favor_miniscule_value_gain
		}
	}
	#Beautiful
	if = {
		limit = { 
			root = {  
				has_trait = beauty_good_3
				age <= 45
			}
		}
		add = {
			#desc = favor_addition_beautiful
			value = favor_ultra_high_value_gain
			add = favor_medium_value_gain
		}
	}
	#########Intelligence, physique and pure_blooded#########
	#Quick
	if = {
		limit = { 
			root = {  
				has_trait = intellect_good_1
			}
		}
		add = {
			#desc = favor_addition_quick
			value = favor_medium_value_gain
		}
	}
	#Intelligent
	if = {
		limit = { 
			root = {  
				has_trait = intellect_good_2
			}
		}
		add = {
			#desc = favor_addition_intelligent
			value = favor_high_value_gain
		}
	}
	#Genius
	if = {
		limit = { 
			root = {  
				has_trait = intellect_good_3
			}
		}
		add = {
			#desc = favor_addition_genius
			value = favor_high_value_gain
		}
	}

	#Hale
	if = {
		limit = { 
			root = {  
				has_trait = physique_good_1
			}
		}
		add = {
			#desc = favor_addition_hale
			value = favor_medium_value_gain
		}
	}
	#Robust
	if = {
		limit = { 
			root = {  
				has_trait = physique_good_2
			}
		}
		add = {
			#desc = favor_addition_robust
			value = favor_high_value_gain
		}
	}
	#Amazonian
	if = {
		limit = { 
			root = {  
				has_trait = physique_good_3
			}
		}
		add = {
			#desc = favor_addition_amazonian
			value = favor_high_value_gain
		}
	}

	#Pure_blooded
	if = {
		limit = { 
			root = {  
				has_trait = pure_blooded
			}
		}
		add = {
			#desc = favor_addition_pure_blooded
			value = favor_ultra_high_value_gain
			add = favor_medium_value_gain
		}
	}

	#########Lineage#########
	#Noble background
	if = {
		limit = { 
			root = {  
				is_lowborn = no
			}
		}
		add = {
			#desc = favor_addition_noble
			value = favor_miniscule_value_gain
		}
	}
	#Child of vassals
	if = {
		limit = { 
			root = {  
				any_close_family_member = {
					is_landed_or_landless_administrative = yes
					highest_held_title_tier >= tier_county
					max_military_strength < scope:harem_liege.max_military_strength
					OR = {
						is_vassal_of = scope:harem_liege
						AND = { #It applies also to fellow powerful vassals
							exists = scope:harem_liege.liege
							liege ?= scope:harem_liege.liege
							OR = {	
								is_powerful_vassal_of = scope:harem_liege.liege
								is_councillor_of = scope:harem_liege.liege
							}
						}
					}
					NAND = { #Dominant families have another calculation
						government_allows = administrative
						house ?= { is_dominant_family = yes }
						OR = {
							AND = {
								exists = scope:harem_liege.top_liege
								top_liege ?= scope:harem_liege.top_liege
							}
							AND = {
								is_vassal_or_below_of = scope:harem_liege
							}
						}
					}
				}
			}
		}
		add = {
			value = favor_miniscule_value_gain
			#desc = favor_addition_good_lineage
			if = {
				limit = { 
					root = {  
						any_close_family_member = {
							is_landed_or_landless_administrative = yes
							OR = {
								is_powerful_vassal_of = scope:harem_liege
								is_councillor_of = scope:harem_liege
								AND = { #It applies also to fellow powerful vassals
									exists = scope:harem_liege.liege
									liege ?= scope:harem_liege.liege
									OR = {	
										is_powerful_vassal_of = scope:harem_liege.liege
										is_councillor_of = scope:harem_liege.liege
									}
								}
							}
						}
					}
				}
				add = favor_medium_value_gain
			}
		}
	}
	#Powerful lineage
	if = {
		limit = { 
			root = {  
				any_close_family_member = {
					is_landed_or_landless_administrative = yes
					OR = {
						is_liege_or_above_of = scope:harem_liege
						max_military_strength >= scope:harem_liege.max_military_strength
						AND = { #Dominant families
							government_allows = administrative
							house ?= { is_dominant_family = yes }
							OR = {
								AND = {
									exists = scope:harem_liege.top_liege
									top_liege ?= scope:harem_liege.top_liege
								}
								AND = {
									is_vassal_or_below_of = scope:harem_liege
								}
							}
						}
					}
				}
			}
		}
		add = {
			#desc = favor_addition_powerful_lineage
			value = favor_ultra_high_value_gain
			add = favor_miniscule_value_gain
		}
	}

	#########Diplomacy#########
	if = {
		limit = { 
			root = {  
				diplomacy >= 13
			}
		}
		add = {
			#desc = favor_diplomacy
			value = favor_miniscule_value_gain
			if = {
				limit = { 
					root = {
						diplomacy >= 16
					}
				}
				add = favor_medium_value_gain
			}
			if = {
				limit = { 
					root = {
						diplomacy >= 21
					}
				}
				add = favor_miniscule_value_gain
			}
		}
	}

	#########Travel#########
	#You're invited to travel
	if = {
		limit = { 
			scope:harem_liege = {
				is_travelling = yes
			}
			root = {
				is_travelling = yes
				current_travel_plan ={
					travel_plan_owner = scope:harem_liege
				}
			}
		}
		add = {
			#desc = favor_addition_invited_consort
			value = favor_miniscule_value_gain
		}
	}

	#########Traits#########
	#root traits
	if = { #Seducer
		limit = { 
			root = {
				has_trait = seducer
			}
		}
		add = favor_medium_value_gain
	}
	if = { #Poet
		limit = { 
			root = {
				has_trait = poet
			}
		}
		add = favor_medium_value_gain
	}
	if = {
		limit = { 
			root = {
				has_trait = lustful
			}
			scope:harem_liege = {
				has_trait = lustful
			}
		}
		add = favor_minor_value_gain
	}
	if = {
		limit = { 
			root = {
				has_trait = gregarious
			}
			scope:harem_liege = {
				has_trait = gregarious
			}
		}
		add = favor_minor_value_gain
	}
	if = { #Chaste
		limit = { 
			root = {
				has_trait = chaste
			}
			scope:harem_liege = {
				has_trait = chaste
			}
		}
		add = favor_minor_value_gain
	}
	if = { #Good genetics
		limit = { 
			root = {
				num_of_good_genetic_traits > 1
			}
		}
		add = {
			#desc = favor_addition_good_genetics
			value = favor_miniscule_value_gain
			if = {
				limit = { 
					root = {
						num_of_good_genetic_traits > 2
					}
				}
				add = favor_miniscule_value_gain
			}
		}
	}

	if = { #Confider
		limit = { 
			root = {
				has_trait = confider
			}
			scope:harem_liege = {
				has_trait = confider
			}
		}
		add = favor_minor_value_gain
	}
	if = { #Athletic
		limit = { 
			root = {
				has_trait = athletic
			}
		}
		add = {
			value = favor_miniscule_value_gain
			if = {
				limit = {
					scope:harem_liege = {
						has_trait = athletic
					}
				}
				add = favor_miniscule_value_gain
			}
		}
	}
	if = { #Improvident
		limit = { 
			root = {
				has_trait = improvident
			}
			scope:harem_liege = {
				NOT = {	
					has_trait = greedy
				}
			}
		}
		add = {
			value = favor_miniscule_value_gain
			if = {
				limit = {
					scope:harem_liege = {
						has_trait = generous
					}
				}
				add = favor_miniscule_value_gain
			}
		}
	}
	
	##Subtractions##

	#########Beauty#########
	#Homely
	if = {
		limit = { 
			root = {
				has_trait = beauty_bad_1
			}
		}
		subtract = {
			#desc = favor_subtraction_homely
			value = favor_minor_value_gain
		}
	}
	#Ugly
	if = {
		limit = { 
			root = {
				has_trait = beauty_bad_2
			}
		}
		subtract = {
			#desc = favor_subtraction_ugly
			value = favor_medium_value_gain
		}
	}
	#Horrendous
	if = {
		limit = { 
			root = {
				has_trait = beauty_bad_3
			}
		}
		subtract = {
			#desc = favor_subtraction_horrendous
			value = favor_high_value_gain
		}
	}

	#########Intelligence and physique#########
	#Slow
	if = {
		limit = { 
			root = {  
				has_trait = intellect_bad_1
			}
		}
		subtract = {
			#desc = favor_subtraction_slow
			value = favor_miniscule_value_gain
		}
	}
	#Stupid
	if = {
		limit = { 
			root = {  
				has_trait = intellect_bad_2
			}
		}
		subtract = {
			#desc = favor_subtraction_stupid
			value = favor_minor_value_gain
		}
	}
	#Imbecile
	if = {
		limit = { 
			root = {  
				has_trait = intellect_bad_3
			}
		}
		subtract = {
			#desc = favor_subtraction_imbecile
			value = favor_minor_value_gain
		}
	}

	#Delicate
	if = {
		limit = { 
			root = {  
				has_trait = physique_bad_1
			}
		}
		subtract = {
			#desc = favor_subtraction_delicate
			value = favor_miniscule_value_gain
		}
	}
	#Frail
	if = {
		limit = { 
			root = {  
				has_trait = physique_bad_2
			}
		}
		subtract = {
			#desc = favor_subtraction_frail
			value = favor_minor_value_gain
		}
	}
	#Feeble
	if = {
		limit = { 
			root = {  
				has_trait = physique_bad_3
			}
		}
		subtract = {
			#desc = favor_subtraction_feeble
			value = favor_minor_value_gain
		}
	}

	#########Diplomacy#########
	if = {
		limit = { 
			root = {
				diplomacy < 7
			}
		}
		subtract = {
			#desc = favor_diplomacy
			value = favor_miniscule_value_gain
			if = {
				limit = { 
					root = {
						diplomacy < 3
					}
				}
				add = favor_miniscule_value_gain
			}
		}
	}

	#########Ageism#########
	if = {
		limit = { 
			root = {
				age >= 30
			}
		}
		subtract = {
			#desc = favor_subtraction_age
			value = {
				value = favor_miniscule_value_gain
				if = {
					limit = { 
						root = {
							age >= 45
						}
					}
					add = favor_miniscule_value_gain
				}
				if = {
					limit = { 
						root = {
							age >= 50
						}
					}
					add = favor_miniscule_value_gain
				}
			}
		}
	}

	#########Unfavored children#########
	if = {
		limit = { 
			root = {
				any_child = { 
					is_child_of = scope:harem_liege
					is_alive = yes
					OR = {	
						has_relation_rival = scope:harem_liege
						has_relation_nemesis = scope:harem_liege
					}
					count > 0
				}
			}
		}
		subtract = {
			#desc = favor_subtraction_unfriendly_children
			value = {
				value = favor_minor_value_gain
				if = {
					limit = { 
						root = {
							any_child = { 
								is_child_of = scope:harem_liege
								is_alive = yes
								has_relation_nemesis = scope:harem_liege
								count >= 1
							}
						}
					}
					add = favor_minor_value_gain
				}
			}
		}
	}

	#########Arrested#########
	if = {
		limit = { 
			root = {
				is_imprisoned_by = scope:harem_liege
				OR = { 
					is_in_prison_type = house_arrest
					is_in_prison_type = dungeon
				}
			}
		}
		subtract = {
			#desc = favor_subtraction_arrest
			value = {
				value = favor_ultra_high_value_gain
				if = {
					limit = { 
						root = {
							is_in_prison_type = house_arrest
						}
					}
					add = favor_minor_value_gain
				}
				else_if = {
					limit = { 
						root = {
							is_in_prison_type = dungeon
						}
					}
					add = favor_miniscule_value_gain
				}
			}
		}
	}

	#########Forbidden lovers#########
	if = {
		limit = {
			scope:harem_liege = {
				NOT = { faith = { has_doctrine = tenet_polyamory } }
			}
			root = {
				OR = {
					has_trait = adulterer
					has_trait = fornicator
				}
				OR = {
					any_relation = {
						type = lover
						NOR = { 
							this = scope:harem_liege
							is_consort_of = root
						}
					}
					any_relation = {
						type = soulmate
						NOR = { 
							this = scope:harem_liege
							is_consort_of = root
						}
					}
				}
			}
		}
		subtract = favor_high_value_gain
	}

	#########Traits#########
	#root traits
	if = { #Craven
		limit = { 
			root = {
				has_trait = craven
			}
			scope:harem_liege = {
				NOR = {
					has_trait = shy
					has_trait = craven
				}
			}
		}
		subtract = {
			#desc = favor_subtraction_craven
			value = favor_miniscule_value_gain
		}
	}
	if = { #Brave
		limit = { 
			root = {
				has_trait = brave
			}
			scope:harem_liege = {
				OR = {
					has_trait = shy
					has_trait = craven
				}
			}
		}
		subtract = {
			#desc = favor_subtraction_brave
			value = favor_miniscule_value_gain
		}
	}
	if = { #Wrathful
		limit = { 
			root = {
				has_trait = wrathful
			}
		}
		subtract = {
			#desc = favor_subtraction_wrathful
			value = favor_miniscule_value_gain
		}
	}
	if = { #Chaste
		limit = { 
			root = {
				has_trait = chaste
			}
			scope:harem_liege = {
				NOT = {
					has_trait = chaste
				}
			}
		}
		subtract = {
			#desc = favor_subtraction_chaste
			value = favor_miniscule_value_gain
		}
	}
	if = { #Lustful
		limit = { 
			root = {
				has_trait = lustful
			}
			scope:harem_liege = {
				has_trait = chaste
			}
		}
		subtract = {
			#desc = favor_subtraction_lustful
			value = favor_miniscule_value_gain
		}
	}
	if = { #Ambitious
		limit = { 
			root = {
				has_trait = ambitious
			}
		}
		subtract = {
			#desc = favor_subtraction_ambitious
			value = favor_miniscule_value_gain
		}
	}
	if = { #Lazy
		limit = { 
			root = {
				has_trait = lazy
			}
		}
		subtract = {
			#desc = favor_subtraction_lazy
			value = favor_miniscule_value_gain
		}
	}
	if = { #Vengeful
		limit = { 
			root = {
				has_trait = vengeful
			}
			scope:harem_liege = {
				OR = {	
					has_trait = forgiving
					has_trait = compassionate
				}
				NOT = {
					has_trait = vengeful
				}
			}
		}
		subtract = {
			#desc = favor_subtraction_vengeful
			value = favor_miniscule_value_gain
		}
	}
	if = { #Greedy
		limit = { 
			root = {
				has_trait = greedy
			}
		}
		subtract = {
			#desc = favor_subtraction_greedy
			value = favor_miniscule_value_gain
		}
	}

	if = { #Shy
		limit = { 
			root = {
				has_trait = shy
			}
			scope:harem_liege = {
				has_trait = gregarious
			}
		}
		subtract = {
			#desc = favor_subtraction_shy
			value = favor_miniscule_value_gain
		}
	}
	if = { #Gregarious
		limit = { 
			root = {
				has_trait = gregarious
			}
			scope:harem_liege = {
				has_trait = shy
			}
		}
		subtract = {
			#desc = favor_subtraction_gregarious
			value = favor_miniscule_value_gain
		}
	}

	if = { #Deceitful
		limit = { 
			root = {
				has_trait = deceitful
			}
			scope:harem_liege = {
				NOT = {	
					has_trait = honest
				}
			}
		}
		subtract = {
			#desc = favor_subtraction_deceitful
			value = favor_miniscule_value_gain
		}
	}

	if = { #Arrogant
		limit = { 
			root = {
				has_trait = arrogant
			}
			scope:harem_liege = {
				has_trait = humble
			}
		}
		subtract = {
			#desc = favor_subtraction_arrogant
			value = favor_miniscule_value_gain
		}
	}
	
	if = { #Arbitrary
		limit = { 
			root = {
				has_trait = arbitrary
			}
			scope:harem_liege = {
				has_trait = just
			}
		}
		subtract = {
			#desc = favor_subtraction_arbitrary
			value = favor_miniscule_value_gain
		}
	}
	if = { #Just
		limit = { 
			root = {
				has_trait = just
			}
			scope:harem_liege = {
				has_trait = arbitrary
			}
		}
		subtract = {
			#desc = favor_subtraction_just
			value = favor_miniscule_value_gain
		}
	}

	if = { #Patient
		limit = { 
			root = {
				has_trait = patient
			}
			scope:harem_liege = {
				has_trait = impatient
			}
		}
		subtract = {
			#desc = favor_subtraction_patient
			value = favor_miniscule_value_gain
		}
	}
	if = { #Impatient
		limit = { 
			root = {
				has_trait = impatient
			}
			scope:harem_liege = {
				has_trait = patient
			}
		}
		subtract = {
			#desc = favor_subtraction_impatient
			value = favor_miniscule_value_gain
		}
	}

	if = { #Gluttonous
		limit = { 
			root = {
				has_trait = gluttonous
			}
		}
		if = {
			limit = {
				scope:harem_liege = {
					has_trait = temperate
				}
			}
			subtract = {
				#desc = favor_subtraction_gluttonous
				value = favor_miniscule_value_gain
			}
		}
		else_if = {
			limit = {
				scope:harem_liege = {
					has_trait = gluttonous
				}
			}
			add = favor_minor_value_gain
		}
	}

	if = { #Zealous
		limit = { 
			root = {
				has_trait = zealous
			}
			scope:harem_liege = {
				has_trait = cynical
			}
		}
		subtract = {
			#desc = favor_subtraction_zealous
			value = favor_miniscule_value_gain
		}
	}
	if = { #Callous
		limit = { 
			root = {
				has_trait = callous
			}
			scope:harem_liege = {
				OR = {	
					has_trait = forgiving
					has_trait = compassionate
				}
			}
		}
		subtract = {
			#desc = favor_subtraction_callous
			value = favor_miniscule_value_gain
		}
	}
	if = { #Sadistic
		limit = { 
			root = {
				has_trait = sadistic
			}
			scope:harem_liege = {
				OR = {	
					has_trait = forgiving
					has_trait = compassionate
				}
			}
		}
		subtract = favor_miniscule_value_gain
	}

	if = { #Fickle
		limit = { 
			root = {
				has_trait = fickle
			}
			scope:harem_liege = {
				has_trait = stubborn
			}
		}
		subtract = {
			#desc = favor_subtraction_fickle
			value = favor_miniscule_value_gain
		}
	}
	if = { #Stubborn
		limit = { 
			root = {
				has_trait = stubborn
			}
			scope:harem_liege = {
				has_trait = fickle
			}
		}
		subtract = {
			#desc = favor_subtraction_stubborn
			value = favor_miniscule_value_gain
		}
	}
	if = { #Eccentric
		limit = { 
			root = {
				has_trait = eccentric
			}
			scope:harem_liege = {
				has_trait = stubborn
			}
		}
		subtract = {
			#desc = favor_subtraction_eccentric
			value = favor_miniscule_value_gain
		}
	}

	if = { #Reclusive
		limit = { 
			root = {
				has_trait = reclusive
			}
		}
		subtract = favor_miniscule_value_gain
	}
	if = { #Wounded
		limit = { 
			root = {
				has_trait = wounded
			}
		}
		subtract = {
			#desc = favor_subtraction_wounded
			value = favor_miniscule_value_gain
		}
	}
	if = { #Bad genetics
		limit = { 
			root = {
				num_of_bad_genetic_traits > 1
			}
		}
		subtract = {
			#desc = favor_subtraction_bad_genetics
			value = {
				value = favor_miniscule_value_gain
				if = {
					limit = { 
						root = {
							num_of_bad_genetic_traits > 2
						}
					}
					add = favor_miniscule_value_gain
				}
			}
		}
	}
	if = { #Bad health
		limit = { 
			root = {
				OR = {
					has_trait = lunatic_1
					has_trait = possessed_1
					has_trait = one_eyed
					has_trait = one_legged
					has_trait = disfigured
					has_trait = eunuch
					has_trait = sickly
					has_trait = infirm
					has_trait = incapable
					has_trait = maimed
					has_trait = blind
					has_trait = ill
					has_trait = bubonic_plague
					has_trait = cancer
					has_trait = consumption
					has_trait = great_pox
					has_trait = gout_ridden
					has_trait = leper
					has_trait = lovers_pox
					has_trait = pneumonic
					has_trait = smallpox
					has_trait = typhus
					has_trait = dysentery
					has_trait = ergotism
					has_trait = measles
				}
			}
		}
		subtract = {
			#desc = favor_subtraction_bad_traits
			value = {
				value = favor_minor_value_gain
				if = { #lunatic_1
					limit = { 
						root = {
							has_trait = lunatic_1
						}
					}
					add = favor_miniscule_value_gain
				}
				if = { #possessed_1
					limit = { 
						root = {
							has_trait = possessed_1
						}
					}
					add = favor_miniscule_value_gain
				}
				if = { #one_legged
					limit = { 
						root = {
							has_trait = one_legged
						}
					}
					add = favor_miniscule_value_gain
				}
				if = { #disfigured
					limit = { 
						root = {
							has_trait = disfigured
						}
					}
					add = favor_minor_value_gain
				}
				if = { #maimed
					limit = { 
						root = {
							has_trait = maimed
						}
					}
					add = favor_minor_value_gain
				}
				if = { #blind
					limit = { 
						root = {
							has_trait = blind
						}
					}
					add = favor_miniscule_value_gain
				}
				if = { #bubonic_plague
					limit = { 
						root = {
							has_trait = bubonic_plague
						}
					}
					add = favor_high_value_gain
				}
				if = { #consumption
					limit = { 
						root = {
							has_trait = consumption
						}
					}
					add = favor_miniscule_value_gain
				}
				if = { #great_pox
					limit = { 
						root = {
							has_trait = great_pox
						}
					}
					add = favor_high_value_gain
				}
				if = { #gout_ridden
					limit = { 
						root = {
							has_trait = gout_ridden
						}
					}
					add = favor_minor_value_gain
				}
				if = { #leper
					limit = { 
						root = {
							has_trait = leper
						}
					}
					add = favor_high_value_gain
				}
				if = { #lovers_pox
					limit = { 
						root = {
							has_trait = lovers_pox
						}
					}
					add = favor_minor_value_gain
				}
				if = { #smallpox
					limit = { 
						root = {
							has_trait = smallpox
						}
					}
					add = favor_medium_value_gain
				}
				if = { #typhus
					limit = { 
						root = {
							has_trait = typhus
						}
					}
					add = favor_medium_value_gain
				}
				if = { #dysentery
					limit = { 
						root = {
							has_trait = dysentery
						}
					}
					add = favor_medium_value_gain
				}
				if = { #ergotism
					limit = { 
						root = {
							has_trait = ergotism
						}
					}
					add = favor_minor_value_gain
				}
				if = { #measles
					limit = { 
						root = {
							has_trait = measles
						}
					}
					add = favor_minor_value_gain
				}
				if = { #Incapable
					limit = { 
						root = {
							has_trait = incapable
						}
					}
					add = favor_ultra_high_value_gain
				}
				if = { #Eunuch
					limit = { 
						root = {
							has_trait = eunuch
						}
					}
					add = favor_medium_value_gain
				}
			}
		}
	}

	if = { #Drunkard
		limit = { 
			root = {
				has_trait = drunkard
			}
			scope:harem_liege = {
				OR = {
					NOT = {	
						has_trait = drunkard
					}
					AND = {	
						has_trait = drunkard
						has_trait = arbitrary
					}
				}
			}
		}
		subtract = favor_miniscule_value_gain
	}
	if = { #Flagellant
		limit = { 
			root = {
				has_trait = flagellant
			}
			scope:harem_liege = {
				OR = {
					NOT = {	
						has_trait = flagellant
					}
					AND = {
						has_trait = flagellant
						has_trait = arbitrary
					}
				}
			}
		}
		subtract = favor_miniscule_value_gain
	}
	if = { #Comfort_eater
		limit = { 
			root = {
				has_trait = comfort_eater
			}
			scope:harem_liege = {
				OR = {
					NAND = {	
						has_trait = comfort_eater
						has_trait = gluttonous
					}
					AND = {	
						OR = {
							has_trait = comfort_eater
							has_trait = gluttonous
						}
						has_trait = arbitrary
					}
				}
			}
		}
		subtract = favor_miniscule_value_gain
	}
	if = { #Contrite
		limit = { 
			root = {
				has_trait = contrite
			}
			scope:harem_liege = {
				OR = {
					NOT = {	
						has_trait = contrite
					}
					AND = {
						has_trait = contrite
						has_trait = arbitrary
					}
				}
			}
		}
		subtract = favor_miniscule_value_gain
	}
	if = { #Improvident
		limit = { 
			root = {
				has_trait = improvident
			}
			scope:harem_liege = {
				has_trait = greedy
			}
		}
		subtract = favor_miniscule_value_gain
	}
	if = { #Inappetetic
		limit = { 
			root = {
				has_trait = inappetetic
			}
			scope:harem_liege = {
				OR = {
					NOT = {	
						has_trait = inappetetic
					}
					AND = {
						has_trait = inappetetic
						has_trait = arbitrary
					}
				}
			}
		}
		subtract = favor_miniscule_value_gain
	}
	if = { #Irritable
		limit = { 
			root = {
				has_trait = irritable
			}
		}
		subtract = favor_minor_value_gain
	}
	if = { #Rakish
		limit = { 
			root = {
				has_trait = rakish
			}
		}
		subtract = {
			value = favor_minor_value_gain
			if = {
				limit = {
					scope:harem_liege = {
						has_trait = chaste
					}
				}
				add = favor_miniscule_value_gain
			}
		}
	}
	if = { #Hashishiyah
		limit = { 
			root = {
				has_trait = hashishiyah
			}
			scope:harem_liege = {
				OR = {
					NOT = {	
						has_trait = hashishiyah
					}
					AND = {
						has_trait = hashishiyah
						has_trait = arbitrary
					}
				}
			}
		}
		subtract = favor_miniscule_value_gain
	}
	if = { #Profligate
		limit = { 
			root = {
				has_trait = profligate
			}
			scope:harem_liege = {
				OR = {
					NOT = {	
						has_trait = profligate
					}
					AND = {
						has_trait = profligate
						has_trait = arbitrary
					}
				}
			}
		}
		subtract = {
			value = favor_miniscule_value_gain
			if = {
				limit = {
					scope:harem_liege = {
						has_trait = greedy
					}
				}
				add = favor_miniscule_value_gain
			}
		}
	}

	#Harem_liege traits#
	if = { #Zealous
		limit = { 
			root = {
				has_trait = cynical
			}
			scope:harem_liege = {
				has_trait = zealous
			}
		}
		subtract = {
			#desc = favor_subtraction_cynical
			value = favor_miniscule_value_gain
		}
	}
	if = { #Infidel
		limit = { 
			scope:harem_liege = {
				OR = {
					AND = {
						has_trait = zealous
						faith = {
							faith_hostility_level = {
								target = root.faith
								value >= faith_astray_level
							}
						}
					}
					AND = {
						NOT = { has_trait = cynical }
						faith = {
							faith_hostility_level = {
								target = root.faith
								value >= faith_hostile_level
							}
						}
					}
				}
			}
		}
		subtract = {
			#desc = favor_subtraction_infidel
			value = favor_miniscule_value_gain
		}
	}

	#########Cultural acceptance#########
	if = { #Foreigner
		limit = { 
			scope:harem_liege = {
				culture = {
					cultural_acceptance = { target = root.culture value < 50 }
				}
				NOR = {
					has_trait = compassionate
					has_trait = forgiving
					has_trait = eccentric
					has_trait = scholar
				}
			}
		}
		subtract = {
			#desc = favor_subtraction_foreigner
			value = favor_miniscule_value_gain
			if = {
				limit = {
					scope:harem_liege.culture = {
						cultural_acceptance = { target = root.culture value < 26 }
					}
				}
				add = favor_miniscule_value_gain
			}
			if = {
				limit = {
					scope:harem_liege.culture = {
						cultural_acceptance = { target = root.culture value < 11 }
					}
				}
				add = favor_miniscule_value_gain
			}
			if = {
				limit = {
					scope:harem_liege = {
						has_trait = paranoid
					}
				}
				add = favor_miniscule_value_gain
			}
		}
	}

	#########Travel#########
	#If you're able to travel and harem liege traveled without you, you're unfavored
	if = {
		limit = { 
			scope:harem_liege = {
				is_travelling = yes
				any_consort = {
					is_travelling = yes
					current_travel_plan ={
						travel_plan_owner = scope:harem_liege
					}
					count > 0
				}
			}
			root = {
				is_travelling = no
				is_diarch = no
				NOR = {
					has_trait = pregnant
					has_trait = ill
					has_trait = wounded
					has_trait = infirm
					has_trait = incapable
					has_trait = maimed
					has_trait = blind
					has_trait = bubonic_plague
					has_trait = cancer
					has_trait = consumption
					has_trait = great_pox
					has_trait = gout_ridden
					has_trait = leper
					has_trait = lovers_pox
					has_trait = pneumonic
					has_trait = smallpox
					has_trait = typhus
					has_trait = dysentery
					has_trait = ergotism
					has_trait = measles
				}
				age <= 50
			}
		}
		subtract = {
			#desc = favor_subtraction_uninvited_consort
			value = favor_medium_value_gain
		}
	}

	round = yes
	floor = yes

	min = forgotten_consort_lower_limit
	max = beloved_consort_upper_limit
}

meddling_relative_parent_age = {
	value = scope:meddling_relative.age
	add = {
		integer_range = {
			min = 16
			max = 20
		}
	}
}

meddling_relative_sibling_age = {
	value = 0
	if = {
		limit = {
			exists = scope:meddling_relative_mother
		}
		add = scope:meddling_relative_mother.age
		subtract = {
			integer_range = {
				min = 16
				max = 20
			}
		}
		add = {
			integer_range = {
				min = -1
				max = 1
			}
		}
	}
	if = {
		limit = {
			NOT = {	
				exists = scope:meddling_relative_mother
			}
		}
		add = scope:meddling_relative.age
		add = {
			integer_range = {
				min = -5
				max = 10
			}
		}
	}
}

##Duchy creation value##
create_duchy_title_value_harem_politics = {
	value = create_duchy_title_value
	multiply = 0.50
}

##Rank difference##
consort_rank_difference_value = {
	value = 0
	if = { #The PS
		limit = {
			exists = scope:harem_liege.primary_spouse
			this = scope:harem_liege.primary_spouse
		}
		if = { #Can recruit the GC?
			limit = {
				scope:target_consort = {
					has_court_position = grand_consort_court_position
				}
			}
			add = 1
		}
		if = { #The SS
			limit = {
				scope:target_consort = {
					NOT = {	
						has_court_position = grand_consort_court_position
					}
					is_spouse_of = scope:harem_liege
				}
			}
			add = {
				value = 1
				if = {
					limit = {
						scope:harem_liege = {
							can_employ_court_position_type = grand_consort_court_position
						}
					}
					add = 1
				}
			}
		}
		if = { #Concubines
			limit = {
				scope:target_consort = {
					NOT = {	
						has_court_position = grand_consort_court_position
					}
					is_concubine_of = scope:harem_liege
				}
			}
			add = {
				value = 1
				if = {
					limit = {
						scope:harem_liege = {
							hp_accepts_polygamy = yes
						}
					}
					add = 1
				}
				if = {
					limit = {
						scope:harem_liege = {
							can_employ_court_position_type = grand_consort_court_position
						}
					}
					add = 1
				}
			}
		}
	}
	else_if = { #The GC
		limit = {
			has_court_position = grand_consort_court_position
		}
		if = { #SS
			limit = {
				scope:target_consort = {
					is_spouse_of = scope:harem_liege
					NOT = {
						this = scope:harem_liege.primary_spouse
					}
				}
			}
			add = 1
		}
		if = { #Concubines
			limit = {
				scope:target_consort = {
					is_concubine_of = scope:harem_liege
				}
			}
			add = {
				value = 1
				if = {
					limit = {
						scope:harem_liege = {
							hp_accepts_polygamy = yes
						}
					}
					add = 1
				}
			}
		}
	}
	else_if = { #SS
		limit = {
			is_spouse_of = scope:harem_liege
			NOT = {
				this = scope:harem_liege.primary_spouse
			}
			scope:target_consort = {
				is_concubine_of = scope:harem_liege
			}
		}
		add = 1
	}
}

# head_of_the_harem_value = {
# 	value = 0
# 	if = {
# 		limit = {
# 			exists = $LIEGE$.mother
# 			this = $LIEGE$.mother
# 		}
# 		add = 1000
# 	}
# 	else_if = {
# 		limit = {
# 			any_sibling = {
# 				any_children = {
# 					this = $LIEGE$
# 				}
# 			}
# 		}
# 		add = 500
# 		add = age
# 	}
# 	else_if = {
# 		limit = {
# 			any_parent = {
# 				this = $LIEGE$
# 			}
# 		}
# 		add = 400
# 		add = age
# 	}
# 	else_if = {
# 		limit = {
# 			exists = $LIEGE$.primary_spouse
# 			this = $LIEGE$.primary_spouse
# 		}
# 		add = 350
# 	}
# 	else_if = {
# 		limit = {
# 			has_court_position = grand_consort_court_position
# 		}
# 		add = 200
# 	}
# 	else_if = {
# 		limit = {
# 			is_spouse_of = $LIEGE$
# 		}
# 		add = 100
# 	}
# 	else_if = {
# 		limit = {
# 			any_parent = {
# 				this = $LIEGE$
# 			}
# 		}
# 		add = age
# 	}
# }

head_of_the_harem_score_value = {
	value = 1
	if = {
		limit = {
			is_valid_harem_member_trigger = {
				LIEGE = scope:harem_liege
			}
		}
		if = {
			limit = {
				scope:harem_liege.religion = religion:islam_religion
				NOT = {
					is_consort_of = scope:harem_liege
				}
			}
			add = 700

			# Mother
			if = {
				limit = {
					is_parent_of = scope:harem_liege
				}
				add = 550
			}
			# Grandmother
			else_if = {
				limit = {
					is_grandparent_of = scope:harem_liege
				}
				add = 700
			}
			# Aunts
			else_if = {
				limit = {
					is_uncle_or_aunt_of = scope:harem_liege
				}
				add = 400
			}
			# Siblings
			else_if = {
				limit = {
					is_sibling_of = scope:harem_liege
				}
				add = 200
			}

			add = age
		}
		else = {
			#Favor
			if = {
				limit = {
					has_variable = favor
				}
				add = var:favor
				divide = 50
			}

			#Rank
			if = {
				limit = {
					exists = scope:harem_liege.primary_spouse
					this = scope:harem_liege.primary_spouse
				}
				add = 550
			}
			if = {
				limit = {
					has_court_position = grand_consort_court_position
				}
				add = 270
			}
			if = {
				limit = {
					is_married = yes
				}
				add = 170
			}

			#Background
			if = {
				limit = {
					any_close_family_member = {
						highest_held_title_tier >= tier_empire
					}
				}
				add = 25
			}
			if = {
				limit = {
					any_close_family_member = {
						highest_held_title_tier = tier_kingdom
					}
				}
				add = 20
			}
			if = { #Dominant families
				limit = {
					any_close_family_member = {
						government_allows = administrative
						house ?= { is_dominant_family = yes }
						OR = {
							AND = {
								exists = scope:harem_liege.top_liege
								top_liege ?= scope:harem_liege.top_liege
							}
							AND = {
								is_vassal_or_below_of = scope:harem_liege
							}
						}
					}
				}
				add = 15
			}
			else_if = {
				limit = {
					any_close_family_member = {
						highest_held_title_tier = tier_duchy
					}
				}
				add = 15
			}

			if = {
				limit = {
					any_close_family_member = {
						highest_held_title_tier = tier_county
					}
				}
				add = 10
			}
			if = {
				limit = {
					any_close_family_member = {
						highest_held_title_tier = tier_barony
					}
				}
				add = 5
			}

			if = { #Powerful families
				limit = {
					any_close_family_member = {
						is_landed_or_landless_administrative = yes
						highest_held_title_tier >= tier_county
						NAND = { #Dominant families have another calculation
							government_allows = administrative
							house ?= { is_dominant_family = yes }
							OR = {
								AND = {
									exists = scope:harem_liege.top_liege
									top_liege ?= scope:harem_liege.top_liege
								}
								AND = {
									is_vassal_or_below_of = scope:harem_liege
								}
							}
						}
					}
				}
				add = {
					value = 0
					if = {
						limit = {
							any_close_family_member = {
								OR = {
									is_powerful_vassal_of = scope:harem_liege
									AND = { #It applies also to fellow powerful vassals
										exists = scope:harem_liege.liege
										liege ?= scope:harem_liege.liege
										is_powerful_vassal_of = scope:harem_liege.liege
									}
								}
							}
						}
						add = 5
					}
					if = {
						limit = {
							any_close_family_member = {
								OR = {
									is_councillor_of = scope:harem_liege
									AND = { #It applies also to fellow powerful vassals
										exists = scope:harem_liege.liege
										liege ?= scope:harem_liege.liege
										is_councillor_of = scope:harem_liege.liege
									}
								}
							}
						}
						add = 5
					}
				}
			}
			if = {
				limit = {
					any_close_family_member = {
						is_knight_of = scope:harem_liege
					}
				}
				add = {
					value = 2
					if = {
						limit = {
							any_close_family_member = {
								is_knight_of = scope:harem_liege
								is_acclaimed = yes
							}
						}
						add = {
							value = 5
						}
					}
				}
			}
			if = {
				limit = {
					any_close_family_member = {
						is_vassal_of = scope:harem_liege
					}
				}
				add = 5
			}
			if = {
				limit = {
					is_lowborn = no
				}
				add = 10
			}

			#Culture and religion
			if = {
				limit = {
					culture = scope:harem_liege.culture
				}
				add = 15
			}
			if = {
				limit = {
					faith = scope:harem_liege.faith
				}
				add = 15
			}

			#Number of children
			if = {
				limit = {
					any_child = {
						is_child_of = scope:harem_liege
						is_alive = yes
						count > 0
					}
				}
				every_child = {
					limit = {
						is_child_of = scope:harem_liege
						is_alive = yes
					}
					add = {
						value = 2
						if = { #Eligible heirs
							limit = {
								character_gender_can_inherit_from_trigger = { CHARACTER = scope:harem_liege }
							}
							add = 1
						}
						if = { #Closer to the throne
							limit = {
								scope:harem_liege.primary_title = {
									place_in_line_of_succession = {
										target = prev
										value <= 3
									}
								}
							}
							add = 1
						}
						if = { #Player heir
							limit = {
								is_player_heir_of = scope:harem_liege
							}
							add = 2
						}
					}
				}
			}
		}
	}
}

primary_spouse_score_value = {
	value = 1
	#Favor
	if = {
		limit = {
			has_variable = favor
		}
		add = var:favor
		divide = 50
	}

	if = {
		limit = {
			has_court_position = grand_consort_court_position
		}
		add = 270
	}
	if = {
		limit = {
			is_married = yes
		}
		add = 170
	}

	#Background
	if = {
		limit = {
			any_close_family_member = {
				highest_held_title_tier >= tier_empire
			}
		}
		add = 25
	}
	if = {
		limit = {
			any_close_family_member = {
				highest_held_title_tier = tier_kingdom
			}
		}
		add = 20
	}
	if = { #Dominant families
		limit = {
			any_close_family_member = {
				government_allows = administrative
				house ?= { is_dominant_family = yes }
				OR = {
					AND = {
						exists = scope:harem_liege.top_liege
						top_liege ?= scope:harem_liege.top_liege
					}
					AND = {
						is_vassal_or_below_of = scope:harem_liege
					}
				}
			}
		}
		add = 15
	}
	else_if = {
		limit = {
			any_close_family_member = {
				highest_held_title_tier = tier_duchy
			}
		}
		add = 15
	}

	if = {
		limit = {
			any_close_family_member = {
				highest_held_title_tier = tier_county
			}
		}
		add = 10
	}
	if = {
		limit = {
			any_close_family_member = {
				highest_held_title_tier = tier_barony
			}
		}
		add = 5
	}

	if = { #Powerful families
		limit = {
			any_close_family_member = {
				is_landed_or_landless_administrative = yes
				highest_held_title_tier >= tier_county
				NAND = { #Dominant families have another calculation
					government_allows = administrative
					house ?= { is_dominant_family = yes }
					OR = {
						AND = {
							exists = scope:harem_liege.top_liege
							top_liege ?= scope:harem_liege.top_liege
						}
						AND = {
							is_vassal_or_below_of = scope:harem_liege
						}
					}
				}
			}
		}
		add = {
			value = 0
			if = {
				limit = {
					any_close_family_member = {
						OR = {
							is_powerful_vassal_of = scope:harem_liege
							AND = { #It applies also to fellow powerful vassals
								exists = scope:harem_liege.liege
								liege ?= scope:harem_liege.liege
								is_powerful_vassal_of = scope:harem_liege.liege
							}
						}
					}
				}
				add = 5
			}
			if = {
				limit = {
					any_close_family_member = {
						OR = {
							is_councillor_of = scope:harem_liege
							AND = { #It applies also to fellow powerful vassals
								exists = scope:harem_liege.liege
								liege ?= scope:harem_liege.liege
								is_councillor_of = scope:harem_liege.liege
							}
						}
					}
				}
				add = 5
			}
		}
	}
	if = {
		limit = {
			any_close_family_member = {
				is_knight_of = root
			}
		}
		add = {
			value = 2
			if = {
				limit = {
					any_close_family_member = {
						is_knight_of = root
						is_acclaimed = yes
					}
				}
				add = {
					value = 5
				}
			}
		}
	}
	if = {
		limit = {
			any_close_family_member = {
				is_vassal_of = root
			}
		}
		add = 5
	}
	if = {
		limit = {
			is_lowborn = no
		}
		add = 10
	}

	#Culture and religion
	if = {
		limit = {
			culture = root.culture
		}
		add = 15
	}
	if = {
		limit = {
			faith = root.faith
		}
		add = 15
	}

	#Number of children
	if = {
		limit = {
			any_child = {
				is_child_of = scope:harem_liege
				is_alive = yes
				count > 0
			}
		}
		every_child = {
			limit = {
				is_child_of = scope:harem_liege
				is_alive = yes
			}
			add = {
				value = 1
				if = { #Eligible heirs
					limit = {
						character_gender_can_inherit_from_trigger = { CHARACTER = scope:harem_liege }
					}
					add = 1
				}
				if = { #Closer to the throne
					limit = {
						scope:harem_liege.primary_title = {
							place_in_line_of_succession = {
								target = prev
								value <= 3
							}
						}
					}
					add = 1
				}
				if = { #Player heir
					limit = {
						is_player_heir_of = scope:harem_liege
					}
					add = 2
				}
			}
		}
	}
}